Hello I am getting flutter firebase web error.
I initialized web properly but I am getting this error when I try to use firebase Firestore functions.
I have no idea about this error ....
Is there anyone who has this error before ?
Thangs for reading.
FirebaseError: Firebase: firebase.firestore() takes either no argument or a Firebase App instance.
(app/invalid-app-argument).
at Object.e [as firestore] (https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js:1:19409)
at Object.getFirestoreInstance
(http://localhost:5000/packages/cloud_firestore_web/src/interop/utils/utils.dart.lib.js:1226:79)
at get [_delegate] (http://localhost:5000/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:778:59)
at cloud_firestore_web.FirebaseFirestoreWeb.new.doc
(http://localhost:5000/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:811:76)
at cloud_firestore.FirebaseFirestore.__.doc
(http://localhost:5000/packages/cloud_firestore/cloud_firestore.dart.lib.js:1456:84)
at database_service.DataBaseServcie.new.read
(http://localhost:5000/packages/root/img_files/img_slider.dart.lib.js:5997:65)
at read.next (<anonymous>)
at runBody (http://localhost:5000/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:5000/dart_sdk.js:40691:7)
at database_service.DataBaseServcie.new.read
(http://localhost:5000/packages/root/img_files/img_slider.dart.lib.js:5992:20)
at http://localhost:5000/packages/timetowork/screen/posting/posting_main_screen.dart.lib.js:15869:44
at [_handleTap] (http://localhost:5000/packages/flutter/src/material/icon_button.dart.lib.js:42254:31)
at tap.TapGestureRecognizer.new.invokeCallback
(http://localhost:5000/packages/flutter/src/gestures/recognizer.dart.lib.js:198:18)
at tap.TapGestureRecognizer.new.handleTapUp
(http://localhost:5000/packages/flutter/src/gestures/tap.dart.lib.js:411:42)
at [_checkUp] (http://localhost:5000/packages/flutter/src/gestures/tap.dart.lib.js:217:12)
at tap.TapGestureRecognizer.new.handlePrimaryPointer
(http://localhost:5000/packages/flutter/src/gestures/tap.dart.lib.js:166:23)
at tap.TapGestureRecognizer.new.handleEvent
(http://localhost:5000/packages/flutter/src/gestures/recognizer.dart.lib.js:444:16)
at [_dispatch] (http://localhost:5000/packages/flutter/src/gestures/pointer_router.dart.lib.js:86:9)
at http://localhost:5000/packages/flutter/src/gestures/pointer_router.dart.lib.js:112:26
at LinkedMap.new.forEach (http://localhost:5000/dart_sdk.js:27745:11)
at [_dispatchEventToRoutes]
(http://localhost:5000/packages/flutter/src/gestures/pointer_router.dart.lib.js:110:29)
at pointer_router.PointerRouter.new.route
(http://localhost:5000/packages/flutter/src/gestures/pointer_router.dart.lib.js:105:37)
at binding$5.WidgetsFlutterBinding.new.handleEvent
(http://localhost:5000/packages/flutter/src/gestures/binding.dart.lib.js:367:26)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent
(http://localhost:5000/packages/flutter/src/gestures/binding.dart.lib.js:355:24)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent
(http://localhost:5000/packages/flutter/src/rendering/layer.dart.lib.js:5440:13)
at [_handlePointerEventImmediately]
(http://localhost:5000/packages/flutter/src/gestures/binding.dart.lib.js:331:14)
at binding$5.WidgetsFlutterBinding.new.handlePointerEvent
(http://localhost:5000/packages/flutter/src/gestures/binding.dart.lib.js:305:43)
at [_flushPointerEventQueue] (http://localhost:5000/packages/flutter/src/gestures/binding.dart.lib.js:295:14)
at [_handlePointerDataPacket] (http://localhost:5000/packages/flutter/src/gestures/binding.dart.lib.js:286:54)
at Object.invoke1 (http://localhost:5000/dart_sdk.js:191747:7)
at _engine.EnginePlatformDispatcher.__.invokeOnPointerDataPacket (http://localhost:5000/dart_sdk.js:171943:15)
at [_onPointerData] (http://localhost:5000/dart_sdk.js:172879:49)
at http://localhost:5000/dart_sdk.js:173317:28
at http://localhost:5000/dart_sdk.js:173273:16
at loggedHandler (http://localhost:5000/dart_sdk.js:172978:11)
run flutter pub upgrade --major-versions
run dart fix --apply
Try upgrading your packages at:
firebase_core: ^1.20.0
cloud_firestore: ^3.4.2
then flutter clean / flutter pub get
Related
I am trying to run a flutter app locally on my web browser (chrome). I do the following steps:
flutter channel stable
flutter config --enable-web
flutter run -d chrome
when I run it, it starts fine, and opens chrome but it doesn't load anything, and then throws this error:
"FirebaseOptions cannot be null when creating the default app."
at Object.throw_ [as throw] (http://localhost:63723/dart_sdk.js:5080:11)
at Object.assertFailed (http://localhost:63723/dart_sdk.js:5005:15)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:63723/packages/firebase_core_web/firebase_core_web.dart.lib.js:252:42)
at initializeApp.next (<anonymous>)
at http://localhost:63723/dart_sdk.js:40641:33
at _RootZone.runUnary (http://localhost:63723/dart_sdk.js:40511:59)
at _FutureListener.thenAwait.handleValue (http://localhost:63723/dart_sdk.js:35438:29)
at handleValueCallback (http://localhost:63723/dart_sdk.js:35999:49)
at _Future._propagateToListeners (http://localhost:63723/dart_sdk.js:36037:17)
at [_completeWithValue] (http://localhost:63723/dart_sdk.js:35872:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:63723/dart_sdk.js:35906:35)
at Object._microtaskLoop (http://localhost:63723/dart_sdk.js:40778:13)
at _startMicrotaskLoop (http://localhost:63723/dart_sdk.js:40784:13)
at http://localhost:63723/dart_sdk.js:36261:9
how would I fix this?
edit:
void main() async{
WidgetsFlutterBinding.ensureInitialized();
setPathUrlStrategy();
await Firebase.initializeApp();
You can reference the Flutter Firebase setup steps here: https://firebase.google.com/docs/flutter/setup?platform=ios
Specifically, make sure you don't miss the following 2 steps:
In the terminal, run flutterfire config
In main.dart, make sure to add this code snippet:
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
As explained here, flutterfire config will auto-create a FirebaseOptions class for you.
Start with firebase init command and follow this
once you are done, you will get firebase_options.dart like t
main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(YourApp());
}
You will use DefaultFirebaseOptions.currentPlatform
I was working on a flutter web app and a power outage broke my firebase options.
Here is the error I get:
Running "flutter pub get" in flutter_tools...
Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
DartUri: Unresolved uri: dart:web_sql
DartUri: Unresolved uri: dart:ui
This app is linked to the debug service: ws://127.0.0.1:52488/knxO4BrQ_6M=/ws
Debug service listening on ws://127.0.0.1:52488/knxO4BrQ_6M=/ws
Running with sound null safety
Debug service listening on ws://127.0.0.1:52488/knxO4BrQ_6M=/ws
Error: Assertion failed:
file:///C:/Users/niema/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_core_web-1.7.3/lib/src/firebase_core_web.dart:207:11
options != null
"FirebaseOptions cannot be null when creating the default app."
at Object.throw_ [as throw] (http://localhost:52440/dart_sdk.js:5069:11)
at Object.assertFailed (http://localhost:52440/dart_sdk.js:4994:15)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:52440/packages/firebase_core_web/firebase_core_web.dart.lib.js:226:42)
at initializeApp.next (<anonymous>)
at http://localhost:52440/dart_sdk.js:40627:33
at _RootZone.runUnary (http://localhost:52440/dart_sdk.js:40497:59)
at _FutureListener.thenAwait.handleValue (http://localhost:52440/dart_sdk.js:35424:29)
at handleValueCallback (http://localhost:52440/dart_sdk.js:35985:49)
at _Future._propagateToListeners (http://localhost:52440/dart_sdk.js:36023:17)
at [_completeWithValue] (http://localhost:52440/dart_sdk.js:35858:23)
at http://localhost:52440/dart_sdk.js:35063:46
at _RootZone.runUnary (http://localhost:52440/dart_sdk.js:40497:59)
at _FutureListener.then.handleValue (http://localhost:52440/dart_sdk.js:35424:29)
at handleValueCallback (http://localhost:52440/dart_sdk.js:35985:49)
at _Future._propagateToListeners (http://localhost:52440/dart_sdk.js:36023:17)
at [_completeWithValue] (http://localhost:52440/dart_sdk.js:35858:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:52440/dart_sdk.js:35892:35)
at Object._microtaskLoop (http://localhost:52440/dart_sdk.js:40764:13)
at _startMicrotaskLoop (http://localhost:52440/dart_sdk.js:40770:13)
at http://localhost:52440/dart_sdk.js:36247:9
Here is what I have tried to fix it:
deleted pubspec.lock because it gave some long binary error of 001001
ran a flutter clean and flutter pub get
deleted pub cache in flutter folder
deleted cache folder located in C:/Users/niema/AppData/Local/Pub
cloned the project again from github
Run flutter channel stable
Run flutter upgrade
Replace await Firebase.initializeApp() with await Firebase.initializeApp( options: const FirebaseOptions( apiKey: "XXX", appId: "XXX", messagingSenderId: "XXX", projectId: "XXX", ), );
Restart the app.
Or if that doesn't work, there's another thread that treats the same error here: https://stackoverflow.com/a/70234018/7156819
When I was coding in Flutter on Android Studio Chipmunk 2021.2.1, a new windows of server's certificate is not trusted appeared, I didn't know what to do, I thought that was a kind of attack so I declined the certificate. But know, after closing and reopening the app, when I build it, nothing more screen in the Chrome(web) built environment with a error that I think was already there before when the app was screening good (I am in unsound null safety mode). This is the error :
Error: Unexpected null value.
at Object.throw_ [as throw] (http://localhost:65099/dart_sdk.js:5405:11)
at Object.nullCheck (http://localhost:65099/dart_sdk.js:5732:30)
at get user (http://localhost:65099/packages/epressing/profile_folder/profile_edit_page.dart.lib.js:1252:19)
at desc.get [as user] (http://localhost:65099/dart_sdk.js:5906:17)
at get myUser (http://localhost:65099/packages/epressing/profile_folder/profile_edit_page.dart.lib.js:1222:73)
at desc.get [as myUser] (http://localhost:65099/dart_sdk.js:5906:17)
at new main.MyApp.new (http://localhost:65099/packages/epressing/auth_folder/login_widget.dart.lib.js:1078:48)
at main$ (http://localhost:65099/packages/epressing/auth_folder/login_widget.dart.lib.js:1119:22)
at main$.next (<anonymous>)
at http://localhost:65099/dart_sdk.js:43063:33
at _RootZone.runUnary (http://localhost:65099/dart_sdk.js:42919:58)
at _FutureListener.thenAwait.handleValue (http://localhost:65099/dart_sdk.js:37493:29)
at handleValueCallback (http://localhost:65099/dart_sdk.js:38088:49)
at _Future._propagateToListeners (http://localhost:65099/dart_sdk.js:38126:17)
at [_completeWithValue] (http://localhost:65099/dart_sdk.js:37955:23)
at http://localhost:65099/dart_sdk.js:37112:46
at _RootZone.runUnary (http://localhost:65099/dart_sdk.js:42919:58)
at _FutureListener.then.handleValue (http://localhost:65099/dart_sdk.js:37493:29)
at handleValueCallback (http://localhost:65099/dart_sdk.js:38088:49)
at _Future._propagateToListeners (http://localhost:65099/dart_sdk.js:38126:17)
at [_completeWithValue] (http://localhost:65099/dart_sdk.js:37955:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:65099/dart_sdk.js:37991:35)
at Object._microtaskLoop (http://localhost:65099/dart_sdk.js:43223:13)
at _startMicrotaskLoop (http://localhost:65099/dart_sdk.js:43229:13)
at http://localhost:65099/dart_sdk.js:38359:9
When I try to build it with Edge(web) built, that print out another the same error. With Windows(desktop) too they say :
Exception: No Windows desktop project configured. See https://docs.flutter.dev/desktop#add-desktop-support-to-an-existing-flutter-app to learn about adding Windows support to a project.
(my computer hardly run with android emulator, so I don't use that).
I've tried to download two kind of google server's certificate on internet (which is in apk type) and add them, but that didn't appeared in the little windows of choosing files or folder certificate path in the
Files > Setting > Tools > Server Certificate > Add
How can i proceed to add a server certificate if that is the problem and necessary, or how can i solve my problem ?
Unsupported operation: default Security Context getter at Object.throw_ [as throw] (http://localhost:51147/dart_sdk.js:5080:11)
at mongo_dart._ConnectionManager.new.open (http://localhost:51147/packages/mongo_dart/src/database/utils/split_hosts.dart.lib.js:11102:23)at open.throw ()
I am using dart.io package and trying to detect the current locate of the system using Platform.localeName like this
WidgetsFlutterBinding.ensureInitialized();
String defaultSystemLocale = Platform.localeName;
print('$defaultSystemLocale');
But when I run the app in Chrome (Web), I am getting this error
Error: Unsupported operation: Platform._localeName
at Object.throw_ [as throw] (http://localhost:62284/dart_sdk.js:5061:11)
at Function._localeName (http://localhost:62284/dart_sdk.js:54692:17)
at Function.localeName (http://localhost:62284/dart_sdk.js:54698:71)
at Function.get localeName [as localeName] (http://localhost:62284/dart_sdk.js:54574:27)
at main (http://localhost:62284/packages/testapp/main4.dart.lib.js:97:45)
Any idea why?
If you are getting Platform from dart:io, it is not supported on web (see this website). You can import it from universal_io instead.