scebab
scebab

Reputation: 11

flutter firebase offline error caused by sending get request to real time database

im currently trying to use flutter and firebase realtime database together but i keep on getting this error whenever i try and get or update the database. it was working fine a few days ago but i accidently rolled back the changes.

i have done

WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    name: "main_app",
    options: FirebaseOptions(
        apiKey: "XXXXXXXXXXXXXXXXXXXXXXXX",
        authDomain: "fXXXXXXXXXXXXX",
        databaseURL: "XXXXXXXXXXXXXXX",
        projectId: "XXXXXXXXXXXXXXXXX",
        storageBucket: "XXXXXXXXXXXXXX",
        messagingSenderId: "XXXXXXXXXX",
        appId: "XXXXXXXXXXXXXXXXXXXXX",
        measurementId: "XXXXX"
    )
  );

the error occurs wheneever i do FirebaseDatabase.instance.ref("/users").get() i have tried different end points to check if that is the problem but the error is hard to understand imo

I/RepoOperation( 6096): get for query / falling back to disk cache after error: Client is offline
E/firebase_database( 6096): An unknown error occurred handling native method call Query#get
E/firebase_database( 6096): java.util.concurrent.ExecutionException: java.lang.Exception: Client is offline
E/firebase_database( 6096):     at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@18.0.1:5)
E/firebase_database( 6096):     at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@18.0.1:8)
E/firebase_database( 6096):     at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin.lambda$queryGet$8$FirebaseDatabasePlugin(FirebaseDatabasePlugin.java:248)
E/firebase_database( 6096):     at io.flutter.plugins.firebase.database.-$$Lambda$FirebaseDatabasePlugin$zohedUhq4ZX8w6dhHgizPHWixGY.call(Unknown Source:4)
E/firebase_database( 6096):     at com.google.android.gms.tasks.zzz.run(com.google.android.gms:play-services-tasks@@18.0.1:1)
E/firebase_database( 6096):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/firebase_database( 6096):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/firebase_database( 6096):     at java.lang.Thread.run(Thread.java:919)
E/firebase_database( 6096): Caused by: java.lang.Exception: Client is offline
E/firebase_database( 6096):     at com.google.firebase.database.connection.PersistentConnectionImpl.lambda$get$1$PersistentConnectionImpl(PersistentConnectionImpl.java:441)
E/firebase_database( 6096):     at com.google.firebase.database.connection.-$$Lambda$PersistentConnectionImpl$DHovbqW2nxPacSd_wNZBtpYapws.run(Unknown Source:8)
E/firebase_database( 6096):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
E/firebase_database( 6096):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/firebase_database( 6096):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
E/firebase_database( 6096):     ... 3 more
E/flutter ( 6096): [ERROR:flutter/shell/common/shell.cc(94)] Dart Unhandled Exception: [firebase_database/unknown] java.lang.Exception: Client is offline
E/flutter ( 6096): 
E/flutter ( 6096): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 6096): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter ( 6096): <asynchronous suspension>
E/flutter ( 6096): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:367:43)
E/flutter ( 6096): <asynchronous suspension>
E/flutter ( 6096): #3      MethodChannelQuery.get (package:firebase_database_platform_interface/src/method_channel/method_channel_query.dart:74:22)
E/flutter ( 6096): <asynchronous suspension>
E/flutter ( 6096): #4      Query.get (package:firebase_database/src/query.dart:21:27)
E/flutter ( 6096): <asynchronous suspension>
E/flutter ( 6096): , stack trace: #0      MethodChannelQuery.get (package:firebase_database_platform_interface/src/method_channel/method_channel_query.dart:86:7)
E/flutter ( 6096): <asynchronous suspension>
E/flutter ( 6096): #1      Query.get (package:firebase_database/src/query.dart:21:27)
E/flutter ( 6096): <asynchronous suspension>
E/flutter ( 6096): 

Upvotes: 0

Views: 752

Answers (3)

Ifrah Tahir
Ifrah Tahir

Reputation: 1

I have just set read and write permissions to true in Realtime database rules and it worked for me.

Upvotes: 0

vinchuli
vinchuli

Reputation: 545

What I did and it worked for me. Just

  1. flutter pub clean.
  2. uninstall the app on your device.
  3. flutter pub get

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 598807

You seem to be calling get(), while you're offline and with no data in the cache.

Keep in mind you have to explicitly enable disk persistence for the Firebase Realtime Database before it can read data from it while you're offline. You can do this by calling setPersistenceEnabled(true) at the start of the app, before calling any methods that read/write data:

FirebaseDatabase.instance.setPersistenceEnabled(true);

Upvotes: 1

Related Questions