skip to Main Content

I want to make the user to access firestore data in my flutter app only when they are online.

I am expecting that firestore data can’t stored in cache memory, so tha tthe user only gets the data when they are online.

3

Answers


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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search