7.8 C
London
Sunday, February 11, 2024

ios – Firebase Flutter Refresh concern


I’ve a dwell Flutter App that makes use of firebase Datastore.

  • When the person is logged out and I make adjustments to the person doc and the person logs again within the adjustments I’ve made within the firestore database keep. ( Right operate )

  • When the person is logged in and utilizing the app and I make adjustments to the person doc the adjustments I’ve made within the firestore database keep. ( Right operate )

  • ** When the person is logged in and backgrounds the app by utilizing one other app or locking the cellphone and I make adjustments to the person doc then the person resumes the app the information I’ve modified within the person doc reverts to the outdated information. ** ( incorrect operate ) this solely occurs on an actual machine and never and emulator.

What’s the concern I’ve tried incorporating this code in the principle then i attempted incorporating it in different screens of the app. Despatched to check flight and concern continues to be current.


@override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    tremendous.didChangeAppLifecycleState(state);
    if (state == AppLifecycleState.resumed) {
      userState.refreshUserData();
      topicsManager();
      print('App resumed - refreshing information');
    }
  } 


  @motion
  Future<void> refreshUserData() async {
    attempt {
      print('Refreshing person information...');

      last docSnapshot = await FirebaseFirestore.occasion
          .assortment(USERS_COLLECTION)
          .doc(docId) // Guarantee 'docId' is appropriately set
          .get(GetOptions(
              supply: Supply.server)); 

      if (docSnapshot.exists) {
        Map<String, dynamic> latestUserData =
            docSnapshot.information() as Map<String, dynamic>;
        Map<String, dynamic> latestUserBeeInfo =
            latestUserData['beeInfo'] as Map<String, dynamic>;
        String? latestBeeType = latestUserBeeInfo['beeType'];

        // Immediately evaluate mandatory fields or make the most of a technique if advanced logic is required
        // For simplicity, assuming direct area checks right here:
        if (me.displayName != latestUserData['displayName'] ||
            me.e-mail != latestUserData['email'] ||
            me.userBeeInfoField.beeType != latestBeeType) {
          loadUser(latestUserData, docId);
          print('Person information up to date with contemporary information.');
        } else {
          print('No adjustments in person information detected.');
        }
      } else {
        print('Person information doc doesn't exist.');
      }
    } catch (e) {
      print('Error refreshing person information: $e');
    }
  }

What's the concern I've tried incorporating this code in the principle then i attempted incorporating it in different screens of the app. Despatched to check flight and concern continues to be current.  

 @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    tremendous.didChangeAppLifecycleState(state);
    if (state == AppLifecycleState.resumed) {
      userState.refreshUserData();
      topicsManager();
      print('App resumed - refreshing information');
    }
  } 


  @motion
  Future<void> refreshUserData() async {
    attempt {
      print('Refreshing person information...');

      last docSnapshot = await FirebaseFirestore.occasion
          .assortment(USERS_COLLECTION)
          .doc(docId) // Guarantee 'docId' is appropriately set
          .get(GetOptions(
              supply: Supply.server)); 

      if (docSnapshot.exists) {
        Map<String, dynamic> latestUserData =
            docSnapshot.information() as Map<String, dynamic>;
        Map<String, dynamic> latestUserBeeInfo =
            latestUserData['beeInfo'] as Map<String, dynamic>;
        String? latestBeeType = latestUserBeeInfo['beeType'];

        // Immediately evaluate mandatory fields or make the most of a technique if advanced logic is required
        // For simplicity, assuming direct area checks right here:
        if (me.displayName != latestUserData['displayName'] ||
            me.e-mail != latestUserData['email'] ||
            me.userBeeInfoField.beeType != latestBeeType) {
          loadUser(latestUserData, docId);
          print('Person information up to date with contemporary information.');
        } else {
          print('No adjustments in person information detected.');
        }
      } else {
        print('Person information doc doesn't exist.');
      }
    } catch (e) {
      print('Error refreshing person information: $e');
    }
  } 

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here