Created
August 4, 2022 11:48
-
-
Save nbnD/6a56f2ff84a480e37d224552e6e6d7c2 to your computer and use it in GitHub Desktop.
flutter hive
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 'dart:io'; | |
import 'package:flutter/material.dart'; | |
import 'package:hive/hive.dart'; | |
import './data_model.dart'; | |
import 'package:path_provider/path_provider.dart' as pathProvider; | |
import 'homepage.dart'; | |
void main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
Directory directory = await pathProvider.getApplicationDocumentsDirectory(); | |
Hive.init(directory.path); | |
Hive.registerAdapter(DataModelAdapter()); | |
await Hive.openBox('hive_box'); | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const HomePage(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment