initFlutter method
Future<void>
initFlutter([
- String? subDir,
- HiveStorageBackendPreference backendPreference = HiveStorageBackendPreference.native,
- int? colorAdapterTypeId,
- int? timeOfDayAdapterTypeId,
Initializes Hive with the path from getApplicationDocumentsDirectory
.
You can provide a subDir
where the boxes should be stored.
Also registers the flutter type adapters.
Implementation
Future<void> initFlutter([
String? subDir,
HiveStorageBackendPreference backendPreference =
HiveStorageBackendPreference.native,
int? colorAdapterTypeId,
int? timeOfDayAdapterTypeId,
]) async {
WidgetsFlutterBinding.ensureInitialized();
String? path;
if (!kIsWeb) {
final appDir = await getApplicationDocumentsDirectory();
path = path_helper.join(appDir.path, subDir);
}
init(
path,
backendPreference: backendPreference,
);
final colorAdapter = ColorAdapter(typeId: colorAdapterTypeId);
if (!isAdapterRegistered(colorAdapter.typeId)) {
registerAdapter(colorAdapter);
}
final timeOfDayAdapter = TimeOfDayAdapter(typeId: timeOfDayAdapterTypeId);
if (!isAdapterRegistered(timeOfDayAdapter.typeId)) {
registerAdapter(timeOfDayAdapter);
}
}