Home > Software design >  how to make firestore data online only?
how to make firestore data online only?

Time:11-23

I want to make the user to access firestore data in my flutter app only when they are online. hope for positive response...ignore my poor English.

I am expecting that firestore data can't stored in cache memory. user only get the data when they are online.

CodePudding user response:

you can check the internet by using connectivity_plus: ^3.0.2 package and with this package u can apply ur logic regarding connectivity...

CodePudding user response:

you can check the internet by using connectivity_plus: ^3.0.2 package so you can disable delete button if there is no internet

Your code will be like this:

YourAppState{
    ConnectivityResult _connectionStatus = ConnectivityResult.none;
    final Connectivity _connectivity = Connectivity();
    late StreamSubscription<ConnectivityResult> _connectivitySubscription;

  @override
   void initState() {
   super.initState();
   _connectivitySubscription_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
  }

   Future<void> _updateConnectionStatus(ConnectivityResult result) async {
     setState(() {
       _connectionStatus = result;
     });
      if (_connectionStatus.toString() == "ConnectivityResult.none") {
         navigatorKey.currentState!.popUntil((route) => route.isFirst);
        }
    }

}

Then up your widget write this condition

if(_connectionStatus.toString() != "ConnectivityResult.none") 

now if there is no internet connection the widget will not appear

CodePudding user response:

It sounds like your question is just asking how to disable any persistence to confirm that your app is only receiving up-to-date data. You can configure that with your Firebase settings. Below is a snippet of code from the documentation.

// Apple and Android
db.settings = const Settings(persistenceEnabled: true);

// Web
await db
    .enablePersistence(const PersistenceSettings(synchronizeTabs: true));

More information can be found on the Access data offline documentation

  • Related