This Flutter project provides a reusable, singleton class, HiveDb, to handle Hive database operations. The class manages the initialization, configuration, and CRUD operations on a database, allowing developers to define their own data models and manage user accounts, pizzas, and invoices dynamically.
Ensure you have Flutter installed and set up on your machine. You will also need to include the following dependencies in your pubspec.yaml
file:
dependencies:
flutter:
sdk: flutter
hive: ^2.0.0
hive_flutter: ^1.1.0
path_provider: ^2.0.10
dev_dependencies:
build_runner: ^2.4.11
hive_generator: ^2.0.1
Clone the repository or copy the HiveDb class into your Flutter project.
Run the build_runner command in your terminal:
dart run build_runner build
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await HiveDb().initializeDatabase();
runApp(MyApp());
}
You can easily customize the database structure by modifying the user, pizza, and invoice classes as needed. This makes HiveDb
suitable for a variety of applications, from simple projects to more complex systems with unique data requirements.
For any questions or feedback, please reach out via email: [email protected]