This is a most likely a transient condition and may be corrected by retrying with a backoff
R

11

26

I'm using firebase in my project and i got some issues mentioned below -

[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.

I'm using firebase lib version :

 firebase_auth: ^0.18.0+1
 google_sign_in: ^4.5.3
 cloud_firestore: ^0.14.3
 firebase_core: ^0.5.2
 firebase_messaging: ^7.0.3
 firebase_storage: ^4.0.0

flutter run --verbose - result :

     [ +208 ms] executing: [/home/loser97/Desktop/application/flutter/flutter_linux/flutter/] git -c
log.showSignature=false log -n 1 --pretty=format:%H
[ +472 ms[        ] f30b7f4db93ee747cd727df747941a28ead25ff5log -n 1 --pretty=format:%H
[   +1 ms] executing: [/home/loser97/Desktop/application/flutter/flutter_linux/flutter/] git tag --points-at HEAD
[+1208 ms] Exit code 0 from: git tag --points-at HEAD
[        ] 1.22.0-12.4.pre
           1.22.1
[  +14 ms] executing: [/home/loser97/Desktop/application/flutter/flutter_linux/flutter/] git rev-parse --abbrev-ref
--symbolic @{u}
[  +38 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [/home/loser97/Desktop/application/flutter/flutter_linux/flutter/] git ls-remote --get-url
origin
[   +9 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +83 ms] executing: [/home/loser97/Desktop/application/flutter/flutter_linux/flutter/] git rev-parse --abbrev-ref
HEAD
[   +6 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[ +157 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[  +20 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +162 ms] executing: /home/loser97/Android/Sdk/platform-tools/adb devices -l
[  +52 ms] List of devices attached
[   +3 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[ +158 ms] No supported devices connected.
[  +14 ms] "flutter run" took 502ms.
[  +28 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
           #1      RunCommand.validateCommand (package:flutter_tools/src/commands/run.dart:353:7)
           <asynchronous suspension>
           #2      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:933:11)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure>
(package:flutter_tools/src/runner/flutter_command.dart:836:33)
           <asynchronous suspension>
           #4      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart)
           #5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:29)
           #6      _rootRun (dart:async/zone.dart:1190:13)
           #7      _CustomZone.run (dart:async/zone.dart:1093:19)
           #8      _runZoned (dart:async/zone.dart:1630:10)
           #9      runZoned (dart:async/zone.dart:1550:10)
           #10     AppContext.run (package:flutter_tools/src/base/context.dart:149:18)
           #11     FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:825:20)
           #12     CommandRunner.runCommand (package:args/command_runner.dart:197:27)
           #13     FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:335:21)
           #14     _rootRunUnary (dart:async/zone.dart:1198:47)
           #15     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
           #16     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
           #17     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
           #18     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
           #19     Future._completeWithValue (dart:async/future_impl.dart:529:5)
           #20     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
           #21     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
           #22     FlutterVersion.checkFlutterVersionFreshness (package:flutter_tools/src/version.dart)
           #23     _rootRunUnary (dart:async/zone.dart:1198:47)
           #24     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
           #25     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
           #26     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
           #27     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
           #28     Future._completeWithValue (dart:async/future_impl.dart:529:5)
           #29     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
           #30     _rootRun (dart:async/zone.dart:1190:13)
           #31     _CustomZone.run (dart:async/zone.dart:1093:19)
           #32     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
           #33     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
           #34     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
           #35     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
           #36     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
           #37     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
           
           
[ +258 ms] ensureAnalyticsSent: 252ms
[   +3 ms] Running shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 1

please share your answer.

Rumba answered 17/11, 2020 at 12:38 Comment(4)
Welcome to Stack Overflow, Sonu Saini! I recommend you to read "How do I ask a good question" and you should provide a minimal reproducible example. With that, some user could help you better.Crownwork
Any updates i am also getting this issue in android and i am using macClabber
I'm getting this as well...Copolymerize
Have the same issue on Mac with iOS Emulator - doesn't matter if I use the firebase emulator or try to connect to live firestore (cloud).Ostyak
S
7

This answer might be quite late, but whoever visits here for this error, I have few things to tell,

  1. If you are operating with your features, make sure it is connected to internet for firebase operations.

  2. If your module works with firebase with offline support, make sure you have the collection and all documents which are related to your module cached first. That way you can avoid this error. If offline mode included, clearly you might have enabled the persistance in firebase, if not then please go through this link.

  3. If working offline and above is not working, make sure to check and verify the presence of collection/document in firebase.

  4. You can also utilise the alternatives such as try...catch... and play around for fixing.

  5. There might be a chance of glitch from server's end for which we cannot do much.

In majority of the case there might be some code issue from our end, You can verify it by checking other firebase calls to confirm whether it is from server side fault or not.

Stoical answered 6/1, 2022 at 12:53 Comment(0)
M
2

For me, the issue is happening in the real device, in which the internet connection is low or no When a strong Wifi/Mobile network is there, it's not showing.

Also I wrap all my firestore-functions in a service.dart file with try & catch blocks, so this is not a major problem for me, but anyone who think this as a major issue can try out the below codes.

Note: This is not useful for everyone, may be for someone. Plugins:

fluttertoast:
cloud_firestore:

FirestoreService.dart:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:myproject/Widgets/Widgets.dart';

class FirestoreService {
  
  FirestoreService._privateConstructor();
  static final FirestoreService _instance = FirestoreService._privateConstructor();
  static FirestoreService get instance => _instance;


  static FirebaseFirestore firestore = FirebaseFirestore.instance;

  static DocumentReference? _getReference(String? documentPath, String? collection, String? documentID) {
    if(documentPath!=null) return firestore.doc(documentPath);
    if(collection!=null && documentID!=null) return firestore.collection(collection).doc(documentID);
    return null;
  }

  static Future<DocumentSnapshot?> get({String? documentPath, String? collection, String? documentID}) async {
    DocumentSnapshot? documentSnapshot;
    
    try {
      DocumentReference? reference = _getReference(documentPath, collection, documentID);
      if(reference!=null) documentSnapshot = await reference.get();
    } catch (exception) {
      Widgets.showToast("Error $exception");
    }
    return documentSnapshot;
  }

  static Future<DocumentReference?> add(String collectionPath, Map<String, dynamic> dataMap) async {
    CollectionReference reference = firestore.collection(collectionPath);
    DocumentReference? documentReference;
    try {
      documentReference = await reference.add(dataMap);
    } catch (exception) {
     Widgets.showToast("Error $exception");
    }
    return documentReference;
  }

  static Future<bool> set({required Object? dataMap, String? documentPath, String? collection, String? documentID}) async {
    DocumentReference? reference = _getReference(documentPath, collection, documentID);
    bool created = false;
    try {
      if(reference!=null){
        await reference.set(dataMap, SetOptions(merge: true));
        created = true;
      }
    } catch (exception) {
       Widgets.showToast("Error $exception");
    }
    return created;
  }

  static Future<bool> update({ required Map<String, dynamic> dataMap, String? documentPath, String? collection, String? documentID, DocumentReference? reference}) async {
    bool updated = false;
    DocumentReference? _reference =  reference ?? _getReference(documentPath, collection, documentID);
    try {
      await firestore.runTransaction((transaction) async {
        try {
          if(_reference!=null){
            transaction.update(_reference, dataMap);
            updated = true;
          }
        } catch (exception) {
            updated = false;
           Widgets.showToast("Error $exception");
        }
      });
    } catch (exception) {
      updated = false;
      Widgets.showToast("Error $exception");
    }
    return updated;
  }

  static Future<bool> delete(DocumentReference reference) async {
    bool deleted = false;
    try {
      await reference.delete();
      deleted = true;
    } catch (exception) {
       Widgets.showToast("Error $exception");
    }
    return deleted;
  }
}
Madelyn answered 27/4, 2022 at 5:0 Comment(0)
R
1

One can try this com.google.gms:google-services:4.3.3 Please focus on version

Ritter answered 9/8, 2022 at 3:40 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Pemberton
O
1

Add the latest google-services dependency (which is 4.3.3 as of now) to your project-level build.gradle like so:

buildscript {
    ...
    dependencies {
        ...
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.3'
        // END: FlutterFire Configuration
        ...
    }
    ...
}
...

Oxcart answered 4/2, 2023 at 5:9 Comment(0)
L
1

I got this error and doing the backoff approach.

Using retry package.

Sample of retrying un any exception case:

  @override
  Future<DocumentReference<T>?> add(T data, {String? documentId}) async {
    const retryOp = RetryOptions(maxAttempts: 2);
    final response = await retryOp.retry(
      () async {
        var collection = getCollectionReference().withConverter(
          fromFirestore: fromFirestore,
          toFirestore: toFirestore,
        );

        if (documentId != null) {
          var document = collection.doc(documentId);
          await document.set(data);
          return document;
        }
        return collection.add(data);
      },
      retryIf: (e) => true, // retry any case
    );

    return response;
  }
Licastro answered 16/4 at 2:39 Comment(0)
S
0

On emulator: wipe out emulator data then load the app. On phone: turn off the data then restart your phone then turn on the data and load the app

I solved the issue with this

Sunlight answered 26/4, 2021 at 18:7 Comment(3)
I am facing this problem in 5 different devices, how can I fix it by restarting my deviceKrasnoff
@Hamza Ali have you tried my solution? if not work then check the internet connection on your devices.Sunlight
It is not workingContumacy
I
0

If anyone getting this error on a real device then at least try this solution.

Make sure you have enabled internet permission in main AndroidManifest.xml file. .

Try setting the minifyEnabled and shirnkResources flags to false in the android/app/build.gradle.

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.debug
        shrinkResources false
        minifyEnabled false
    }
}

This worked for me.

I took help from the below link and you can find other solution for this topic on this page too.

https://github.com/FirebaseExtended/flutterfire/discussions/5708#discussioncomment-925997

Igor answered 10/10, 2021 at 20:5 Comment(0)
O
0

In my case , the problem was that i was trying to use offline persistence without caching the data first . So , make sure you have fetched first before trying to access cached data.

Outrigger answered 30/9, 2023 at 10:17 Comment(1)
Your solution worked for me too. I was trying to use offline persistence without fetching the data first. Thanks for the tip!Estriol
B
0

While there are many great answers, for me specifically it happened when I accidentally forgot to make the app connect to Firebase instead of the Firebase Emulator.

Here is an example for connecting to a local firebase server:

FirebaseFirestore.instance.settings = const Settings(
  host: '10.0.2.2:8080',
  sslEnabled: false,
);

It may cause the following error if you don't have a local firebase emulator running.

[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.

If you wish to connect to the remote firebase server, just remove or comment the code that makes it connect to the local server (like the code above)

Burner answered 3/6 at 18:45 Comment(0)
C
-1
await FirebaseFirestore.instance.disableNetwork();
await FirebaseFirestore.instance.enableNetwork();

add this before you call .get()

Cavetto answered 30/3, 2022 at 9:41 Comment(3)
It didn't work for me.Beirut
I tried this but it didn't work.Beirut
This is not the solutionOcana
L
-1

It works for me after wiping my emulator data.

Laomedon answered 14/7, 2023 at 12:58 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Pemberton

© 2022 - 2024 — McMap. All rights reserved.