I'm try to use Firestore with Flutter Deskop (MacOS). But I'm getting always this error since my first try for a month.
[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 wish to get name value from myDocument on Firebase
main.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp()
.then((value) => print("connected " + value.options.asMap.toString()))
.catchError((e) => print(e.toString()));
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
FirebaseFirestore firestore = FirebaseFirestore.instance;
void _initializeApp() async {
await Firebase.initializeApp();
}
@override
void initState() {
_initializeApp();
super.initState();
}
@override
Widget build(BuildContext context) {
CollectionReference users =
FirebaseFirestore.instance.collection('myCollection');
return Scaffold(
appBar: AppBar(),
body: FutureBuilder<DocumentSnapshot>(
future: users.doc("myDocument").get(),
builder:
(BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
print(snapshot.error.toString());
return Text(snapshot.error.toString());
}
if (snapshot.connectionState == ConnectionState.done) {
Map<String, dynamic> data = snapshot.data.data();
return Text("Name: ${data['name']}");
}
return Text("loading");
},
),
);
}
}
Run flutter doctor and paste the output below:
Click To Expand
[✓] Flutter (Channel dev, 1.22.0-9.0.pre, on Mac OS X 10.15.5 19F101, locale en-TR)
• Flutter version 1.22.0-9.0.pre at /Users/leventkantaroglu/Development/flutter
• Framework revision 7a43175198 (13 days ago), 2020-08-28 23:18:04 -0400
• Engine revision 07e2520d5d
• Dart version 2.10.0 (build 2.10.0-73.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/leventkantaroglu/Library/Android/sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.5, Build version 11E608c
• CocoaPods version 1.9.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 41.0.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.48.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.14.1
[✓] Connected device (3 available)
• macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.5 19F101
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 85.0.4183.102
• No issues found!
Run flutter pub deps -- --style=compact and paste the output below:
Click To Expand
Dart SDK 2.10.0-73.0.dev
Flutter SDK 1.22.0-9.0.pre
flutter_desktop_macos 1.0.0+1
dependencies:
- cloud_firestore 0.14.0+2 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web]
- cupertino_icons 0.1.3
- firebase_core 0.5.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]
transitive dependencies:
- async 2.5.0-nullsafety [collection]
- boolean_selector 2.1.0-nullsafety [source_span string_scanner]
- characters 1.1.0-nullsafety.2
- charcode 1.2.0-nullsafety
- clock 1.1.0-nullsafety
- cloud_firestore_platform_interface 2.0.1 [flutter meta collection firebase_core plugin_platform_interface]
- cloud_firestore_web 0.2.0+1 [flutter flutter_web_plugins firebase http_parser meta firebase_core cloud_firestore_platform_interface js]
- collection 1.15.0-nullsafety.2
- fake_async 1.1.0-nullsafety [clock collection]
- firebase 7.3.0 [http http_parser js]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- http 0.12.2 [http_parser path pedantic]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- js 0.6.2
- matcher 0.12.10-nullsafety [stack_trace]
- meta 1.3.0-nullsafety.2
- path 1.8.0-nullsafety
- pedantic 1.9.0
- plugin_platform_interface 1.0.2 [meta]
- quiver 2.1.3 [matcher meta]
- sky_engine 0.0.99
- source_span 1.8.0-nullsafety [charcode collection path term_glyph]
- stack_trace 1.10.0-nullsafety [path]
- stream_channel 2.1.0-nullsafety [async]
- string_scanner 1.1.0-nullsafety [charcode source_span]
- term_glyph 1.2.0-nullsafety
- test_api 0.2.19-nullsafety [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0-nullsafety.2 [collection]
- vector_math 2.1.0-nullsafety.2
Hi @kaiserleka,
Can you create a fresh Flutter project and try below steps to see if it works ?
cloud_firestore and firebase_core to pubspec.yaml. Thanks.
Hi @kaiserleka,
Can you create a fresh Flutter project and try below steps to see if it works ?
- Setup a default Flutter project.
I have created a new Flutter project and enabled desktop support.

- Add
cloud_firestoreandfirebase_coretopubspec.yaml.
I have added both of that packages to pubspec.yaml

- Create a project in Firestore. Create a collection. Create a single simple document in that collection.
I have created new Firestore project and created a collection named "testCollection"

- Follow the instructions at https://firebase.flutter.dev/docs/installation/macos to install GoogleService-Info.plist file.
4.1 I have name my named my project




- Initialize Firebase, following the FutureBuilder / Stateful example here:
https://firebase.flutter.dev/docs/overview/#initializing-flutterfire
I have located that stateful example onto my main.dart. When I run it, it works
import 'package:flutter/material.dart';
// Import the firebase_core plugin
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() {
runApp(MaterialApp(home: App()));
}
class App extends StatefulWidget {
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
// Set default `_initialized` and `_error` state to false
bool _initialized = false;
bool _error = false;
// Define an async function to initialize FlutterFire
void initializeFlutterFire() async {
try {
// Wait for Firebase to initialize and set `_initialized` state to true
await Firebase.initializeApp().catchError((e) => print(e));
setState(() {
_initialized = true;
});
} catch (e) {
// Set `_error` state to true if Firebase initialization fails
print(e);
setState(() {
_error = true;
});
}
}
@override
void initState() {
initializeFlutterFire();
super.initState();
}
@override
Widget build(BuildContext context) {
// Show error message if initialization failed
if (_error) {
print("_error : " + _error.toString());
return Scaffold(
body: Center(
child: Text("Error: " + _error.toString()),
),
);
}
// Show a loader until FlutterFire is initialized
if (!_initialized) {
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
return Scaffold(
body: Center(
child: Text("initialized"),
),
);
}
}
- Add import 'package:cloud_firestore/cloud_firestore.dart';
I have added
- Use your code sample provided above.
I have updated my code with firestore. Event I run Firebase.initializeApp(), it says _"[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()"_
import 'package:flutter/material.dart';
// Import the firebase_core plugin
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() {
runApp(MaterialApp(home: App()));
}
class App extends StatefulWidget {
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
// Set default `_initialized` and `_error` state to false
bool _initialized = false;
bool _error = false;
// Define an async function to initialize FlutterFire
void initializeFlutterFire() async {
try {
// Wait for Firebase to initialize and set `_initialized` state to true
await Firebase.initializeApp().catchError((e) => print(e));
setState(() {
_initialized = true;
});
} catch (e) {
// Set `_error` state to true if Firebase initialization fails
print(e);
setState(() {
_error = true;
});
}
}
@override
void initState() {
initializeFlutterFire();
super.initState();
}
@override
Widget build(BuildContext context) {
// Show error message if initialization failed
if (_error) {
print("_error : " + _error.toString());
return Scaffold(
body: Center(
child: Text("Error: " + _error.toString()),
),
);
}
// Show a loader until FlutterFire is initialized
if (!_initialized) {
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
CollectionReference users =
FirebaseFirestore.instance.collection('testCollection');
return Scaffold(
body: Center(
child: Column(children: [
Text("initialized"),
Divider(),
FutureBuilder<DocumentSnapshot>(
future: users.doc("testDocument").get(),
builder: (BuildContext context,
AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
print(snapshot.error.toString());
return Text(snapshot.error.toString());
}
if (snapshot.connectionState == ConnectionState.done) {
Map<String, dynamic> data = snapshot.data.data();
return Text("Value: ${data['testField']}");
}
return Text("loading");
},
),
]),
),
);
}
}

@kaiserleka,
Since firebase_core is the first and foremost important plugin after migration, initializing it is the first step to integrate firebase in your app. You can do that inside main() method itself, like below and see if it works for you.
void main() async {
await Firebase.initializeApp();
runApp(MyApp());
}
@kaiserleka,
Sincefirebase_coreis the first and foremost important plugin after migration, initializing it is the first step to integrate firebase in your app. You can do that inside main() method itself, like below and see if it works for you.void main() async { await Firebase.initializeApp(); runApp(MyApp()); }
I'm getting : [core/not-initialized] Firebase has not been initialized. Please check the documentation for your platform.
bool isFirebaseReady = true;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp().catchError((e) {
isFirebaseReady = false;
print(e);
});
runApp(MaterialApp(home: App()));
}
Why I can't find any complete Flutter Firestore Macos project :(
@kaiserleka - is your macos app in App Sandbox mode, and if so, did you add the com.apple.security.network.client entitlement?
@kaiserleka - is your macos app in App Sandbox mode, and if so, did you add the com.apple.security.network.client entitlement?
I have also added this to entitlement files but still getting : _[core/not-initialized] Firebase has not been initialized. Please check the documentation for your platform._
<key>com.apple.security.network.client</key>
<true/>
My apologies, my comment wasn't very helpful without additional context. I don't know why you are getting the _Firebase has not been initialized._ error. I tried looking through your code, but I'm pretty new to Flutter and wasn't able to spot the issue.
My comment about the entitlement was to address your original problem, which was that you were getting an error message about cloud_firestore being unavailable.
That said, here is a main.dart file that successfully connects to Firestore for me on macos. I imagine all the other setup (pubspec, entitlements, etc) is now similar to mine so I won't paste it all.
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return FutureBuilder(
// Initialize FlutterFire:
future: Firebase.initializeApp(),
builder: (context, snapshot) {
// Check for errors
if (snapshot.hasError) {
return const Text("Error", textDirection: TextDirection.ltr);
}
if (snapshot.connectionState == ConnectionState.done) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
return const Text("Loading", textDirection: TextDirection.ltr);
});
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('mycollection').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading');
return ListView.builder(
itemExtent: 80,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) => ListTile(
title: Row(
children: [
Expanded(
child: Text(
snapshot.data.documents[index].data().toString()),
)
],
)));
}),
);
}
}
That said, here is a main.dart file that successfully connects to Firestore for me on macos. I imagine all the other setup (pubspec, entitlements, etc) is now similar to mine so I won't paste it all.
Could you share those files and related macos files just in case? Your dart code still giving that error @evanpon
I created a new project from scratch, and made the (I think) minimum changes to make it work for Firestore. You can see the repo and look at the commits here: https://github.com/evanpon/macos_firestore. The one piece it doesn't have is the GoogleService-Info.plist file, since you'll need that from your own project.
I'm also looking for a solution to this error. In my case I get it only when my device (Android) is offline. I'm not able to create new documents when offline due to this exception.
Anyone found a solution for this. I have been trying for the last two days and couldnt find a solution.
[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.
it happened recently.
google products always have annoying bugs
Same here.
Used to work like a charm but not anymore.
await Firebase.initializeApp();
await authService.signinAnonymously(); // OK
var documentSnapshot = await FirebaseFirestore.instance.collection('user').doc(deviceId).get(); // HANG
after 10 seconds or so:
The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.
Same error on iOS 14 physical device. Anyone found a solution ?
Same issue on macos with firebase_core 0.5.1 and cloud_firestore 0.14.2
Adding the network client entitlement fixed my issue (com.apple.security.network.client). I'm guessing that App Sandbox mode is the default for macos Flutter apps, so this step should probably be added to the documentation.
Hi, same error here, on physical Android devices. Firestore client throws same error randomly.
[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.
In my case, a network connection of those devices were active. In addition, I already implemented a retry process using the exponential backoff algorithm. However, this issue is not resolved.
Same here. My app was working fine until about 2 weeks ago, and now I'm getting that error about 70% of the times I try and start the app
Make sure that in your android/build.gradle there is classpath 'com.google.gms:google-services:4.3.3'
Emphasis on the version. Took me the whole day
The same is happening here https://github.com/FirebaseExtended/flutterfire/issues/2753
Sadly, it is almost impossible to work with Flutter and Firebase.
Any solution on this?
I also encountered this problem, but the issue has been resolved a few days back on one of my devices.
@Ehesp I would like to confirm that this issue was not limited to FlutterFire, native Android Firebase Apps were not working as well.
I was in contact with Firebase Support, they told me that there are some issues with ISPs on which they are working to get them resolved.
For me, things are working fine now, but once in a couple of weeks, I still face this issue for 5-10 mins. And, I have noticed that when this issue occurs, even YouTube takes a long time in loading.
@nelstein do you mean, as opposed to 4.3.4, or to 3.x?
I am also being hit hard by this error.
I downgraded to cloud_firestore: 0.13.6
And it started working
Most helpful comment
Same here. My app was working fine until about 2 weeks ago, and now I'm getting that error about 70% of the times I try and start the app