Home > Software design >  The service is currently unavailable | Firebase cloud_firestore issue
The service is currently unavailable | Firebase cloud_firestore issue

Time:11-15

When I try Firebase Firestore on my Android device, the error below is occurred.

[cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.

This doesn't happen when I try with emulator even same code.

What I doing

Updated version of firebase packages.

  firebase_core: ^1.10.0
  firebase_auth: ^3.1.4
  cloud_firestore: ^3.1.0

Using FutureBuilder to get fields.

In my StatefulWidget;

  @override
  Widget build(BuildContext context) {
    myInterstitial.load();
    return FutureBuilder(
        future: FirebaseFirestore.instance
            .collection("users")
            .doc(FirebaseAuth.instance.currentUser!.uid)
            .get(),
        builder:
            (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
          if (snapshot.hasError) {
            return Text(snapshot.error.toString());
          }

          if (snapshot.hasData && !snapshot.data!.exists) {
            FirebaseAuth.instance.signOut();
            return const Text("Document does not exist ");
          }

          if (snapshot.connectionState == ConnectionState.done) {
           .............

I don't know why but snapshot.hasError is alaways true, and snapshot.error.toString() returns error above.

I didn't change any code but it works on emulator. However the build (build with $ flutter build appbundle --no-sound-null-safety, $ flutter build apk --no-sound-null-safety and '$ flutter run --no-sound-null-safety') doesn't work better.

The biggest mystery is that everything works correctly in the emulator.

How can I solve this?

flutter doctor -v

    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 400608f101 (8 weeks ago), 2021-09-15 15:50:26 -0700
    • Engine revision 1d521d89d8
    • Dart version 2.15.0 (build 2.15.0-82.2.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at D:\Android
    • Platform android-31, build-tools 29.0.3
    • Java binary at: D:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8 10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.2)
    • Android Studio at D:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8 10-b944.6842174)

[√] VS Code (version 1.62.2)
    • VS Code at C:\Users\yukik\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.28.0

[√] Connected device (4 available)
    • Pixel 5a (mobile)                  • 16121JECB02429 • android-arm64  • Android 12 (API 31)
    • Android SDK built for x86 (mobile) • emulator-5554  • android-x86    • Android 10 (API 29) (emulator)
    • Chrome (web)                       • chrome         • web-javascript • Google Chrome 95.0.4638.69
    • Edge (web)                         • edge           • web-javascript • Microsoft Edge 95.0.1020.44

• No issues found!

CodePudding user response:

I did nothing but the error never shown. Looks time fixed this issue.

  • Related