Sunday, February 11, 2024
HomeiOS Developmentios - Firebase Flutter Refresh concern

ios – Firebase Flutter Refresh concern


I’ve a dwell 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. ( Appropriate perform )

  • 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. ( Appropriate perform )

  • ** When the consumer is logged in and backgrounds the app through the use of one other app or locking the telephone 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 outdated information. ** ( incorrect perform ) this solely occurs on an actual gadget 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 remains 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 consumer information...');

      remaining 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'];

        // Instantly evaluate crucial 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 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 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 remains 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 consumer information...');

      remaining 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'];

        // Instantly evaluate crucial 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 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');
    }
  } 



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments