Skip to content

Instantly share code, notes, and snippets.

@reasje
Last active December 25, 2021 20:40
Show Gist options
  • Save reasje/b5919d2476e1778a2bc208338b8d9f16 to your computer and use it in GitHub Desktop.
Save reasje/b5919d2476e1778a2bc208338b8d9f16 to your computer and use it in GitHub Desktop.
hive_tut main function
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart';
String someRandomName = "someRandomName";
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (kIsWeb) {
Hive.initFlutter();
} else {
// getting the path of the document in the device for accesing the database
final document = await getApplicationDocumentsDirectory();
Hive.init(document.path);
}
await Hive.openBox<String>(someRandomName);
runApp(MyApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment