Last active
March 29, 2020 09:53
-
-
Save paulallies/4d651670b3ab5078b2e5bf0a6991a99f to your computer and use it in GitHub Desktop.
Hive Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:hive/hive.dart'; | |
import 'package:path_provider/path_provider.dart'; | |
import 'package:todo/views/HiveDemo.dart'; | |
void main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
final appDocumentDirectory = await getApplicationDocumentsDirectory(); | |
Hive.init(appDocumentDirectory.path); | |
await Hive.registerAdapter(ContactAdapter()); | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: HiveDemo(), | |
); | |
} | |
@override | |
void dispose() { | |
Hive.close(); | |
super.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment