iOS Development

ios – Firebase Flutter Refresh difficulty

Spread the love


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

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

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

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

What’s the difficulty I’ve tried incorporating this code in the primary then i attempted incorporating it in different screens of the app. Despatched to check flight and difficulty 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 {
    strive {
      print('Refreshing consumer 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'];

        // Straight evaluate obligatory fields or make the most of a way if advanced logic is required
        // For simplicity, assuming direct subject 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 recent information.');
        } else {
          print('No adjustments in consumer information detected.');
        }
      } else {
        print('Person information doc doesn't exist.');
      }
    } catch (e) {
      print('Error refreshing consumer information: $e');
    }
  }

What's the difficulty I've tried incorporating this code in the primary then i attempted incorporating it in different screens of the app. Despatched to check flight and difficulty 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 {
    strive {
      print('Refreshing consumer 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'];

        // Straight evaluate obligatory fields or make the most of a way if advanced logic is required
        // For simplicity, assuming direct subject 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 recent information.');
        } else {
          print('No adjustments in consumer information detected.');
        }
      } else {
        print('Person information doc doesn't exist.');
      }
    } catch (e) {
      print('Error refreshing consumer information: $e');
    }
  } 

Leave a Reply

Your email address will not be published. Required fields are marked *