Question
this is my function to initialize Hive and put some dummy data inside it if its empty , the but the data doesnt gets displayed , what i figured out is that its not even getting called on the hot restarts or reloads not even when i close the app the rebuild it , the only time the when i can see the updated values of the dummyDietPlan is when i uninstall the app and build it again , why is the _initializeHive() is only getting called once in the life time of the app ?
other than this issue , everything else working fine with hive , but just cant figure out why this issue is coming up
Code sample
void initState() {
super.initState();
_initializeHive();
_checkDietIsViewed();
}
Future<void> _initializeHive() async {
if (!isInitialized) {
await HiveService.initHive();
setState(() {
isInitialized = true;
});
}
}
Future<void> _initializeDummyData() async {
final dietPlans = await HiveService.retrieveDietPlan();
if (dietPlans.isEmpty) {
final dummyDietPlan = DietPlan( ... // dummy diet plan inserted
await HiveService.UpdateDietPlan(dummyDietPlan);
await HiveService.printDietPlans();
}
}
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder<List<DietPlan>>(
future: HiveService.retrieveDietPlan(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
} else if (snapshot.hasError) {
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
// Call _initializeHiveAndData() here to handle empty data
_initializeHive();
return Text('No diet plans available.');
} else {
final dietPlans = snapshot.data!;
return ListView.builder(
}
},
),
);
}
}
Question this is my function to initialize Hive and put some dummy data inside it if its empty , the but the data doesnt gets displayed , what i figured out is that its not even getting called on the hot restarts or reloads not even when i close the app the rebuild it , the only time the when i can see the updated values of the dummyDietPlan is when i uninstall the app and build it again , why is the _initializeHive() is only getting called once in the life time of the app ? other than this issue , everything else working fine with hive , but just cant figure out why this issue is coming up
Code sample
Version Platform: iOS, Android
Attaching the before and after reinstallation ScreenShots