hive implementation
save todo in hive first release
This commit is contained in:
27
lib/data/database.dart
Normal file
27
lib/data/database.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
class ToDoDataBase {
|
||||
List todoList = [];
|
||||
|
||||
//reference hive todo box
|
||||
final _myBox = Hive.box('todoBox');
|
||||
|
||||
//init db
|
||||
void createInitialData() {
|
||||
todoList = [
|
||||
["Make Tutorial", true],
|
||||
["Buy car", false],
|
||||
["Buy new wife", true],
|
||||
["buy card", false],
|
||||
];
|
||||
}
|
||||
|
||||
//load data
|
||||
void loadData() {
|
||||
todoList = _myBox.get('todos');
|
||||
}
|
||||
|
||||
void updateData() {
|
||||
_myBox.put('todos', todoList);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user