isar / hive

Lightweight and blazing fast key-value database written in pure Dart.
Apache License 2.0
4.11k stars 409 forks source link

Does not update , unless reinstalled #1232

Open prateev1409 opened 1 year ago

prateev1409 commented 1 year ago

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(
          }
        },
      ),
    );
  }
}

Version Platform: iOS, Android

Attaching the before and after reinstallation ScreenShots

Screenshot (146) Screenshot (147)

Luismi74 commented 1 year ago

Having the same issue here! I am updating it but the user has to reinstall the app which makes it so tedious.