hive
hive copied to clipboard
Flutter: Hive database is working well but when restarting the app the data is disappeared
This is Hive setup in main function that I open a box and also put the registerAdapter as I said in the question that everything is okay but when restarting the app data lost
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Hive.initFlutter();
Hive.registerAdapter(QuestionModelAdapter());
await Hive.openBox<QuestionModel>("saveQuestion");
runApp(const MyApp());
}
This is the class I used in hive class.
import 'package:hive/hive.dart';
part 'question.g.dart';
@HiveType(typeId: 0)
class QuestionModel {
@HiveField(0)
String title;
@HiveField(1)
List<dynamic> options;
QuestionModel({
required this.title,
required this.options,
});
}
Version
- Platform: Android
- Flutter version: [2.0.0]
- Hive version: [2.0.4]
flutter desktop version also has this problem, any update? when reopen the app, the data is lost.
Same issue here.
same issue its not working well
https://github.com/mohhamad-esmaili/Todo/blob/master/lib/controller/event_controller.dart
this two function solves void _eventBoxPutter() async { await _eventBox.put(_eventKey, _events); refreshItems(); }
/// this refresh items by getting again from box void refreshItems() { _events = _eventBox.get(_eventKey) ?? {}; _recycleEvents = _deletedBox.get(_deletedEventKey) ?? <Event>[]; selectedDay.refresh(); update(); }
The same issue is happening also with simple String objects, where an adapter is not needed.