initFlutter method

Future<void> initFlutter({
  1. String? subDirectory,
  2. int? colorAdapterTypeId,
  3. int? timeOfDayAdapterTypeId,
})

Initializes IsolatedHive with the path from getApplicationDocumentsDirectory and the Flutter IsolateNameServer

You can provide a subDirectory where the boxes should be stored

Also registers the flutter type adapters

Implementation

Future<void> initFlutter({
  String? subDirectory,
  int? colorAdapterTypeId,
  int? timeOfDayAdapterTypeId,
}) async {
  WidgetsFlutterBinding.ensureInitialized();

  final appDir = await getApplicationDocumentsDirectory();
  final hivePath = path.join(appDir.path, subDirectory);

  await init(hivePath, isolateNameServer: const IsolateNameServer());

  final colorAdapter = ColorAdapter(typeId: colorAdapterTypeId);
  if (!isAdapterRegistered(colorAdapter.typeId)) {
    registerAdapter(colorAdapter);
  }

  final timeOfDayAdapter = TimeOfDayAdapter(typeId: timeOfDayAdapterTypeId);
  if (!isAdapterRegistered(timeOfDayAdapter.typeId)) {
    registerAdapter(timeOfDayAdapter);
  }
}