Undefined name "Firebase" following "FlutterFire Overview" tutorial - firebase

I follow this page : https://firebase.flutter.dev/docs/overview/#initializing-flutterfire
Then I type the instruction:
await Firebase.initializeApp();
Like in the documentation, I have the error: 'Undefined name 'Firebase'. However, I the import is present in my file:
import 'package:firebase_core/firebase_core.dart';
Plus, when I type FirebaseApp in place of Firebase, FirebaseApp is recognized but not define initializeApp function.
Note that import is displayed as greyed import 'package:firebase_core/firebase_core.dart';
So Where is the problem ?

I've changed the version of each Firebase related packages to the latest ones (because, as suggested, the tutorial is for a new version than 0.4.0) and all works fine.
firebase_core: ^1.0.0
firebase_auth: ^1.0.1
cloud_firestore: ^1.0.3

Related

Flutter can't install firebase onto macOS

I tried to install the firebase package for flutter. After running
flutter pub add firebase_core
It states "successfully installed". When I then try to import it to my main.dart file using the following code, it throws an error.
import 'package:firebase_core/firebase_core.dart';
Target of URI doesn't exist:
'package:firebase_core/firebase_core.dart'. Try creating the file
referenced by the URI, or Try using a URI for a file that does exist.
Thank you for your help!

Flutter: Firebase has not been correctly initialized

I'm working on iPhone 12 Pro Max Emulator, macOS Catalina.
I'm getting this error when I try to run the app:
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.
Also there is a tip in the console:
Usually this means you've attempted to use a Firebase service before calling Firebase.initializeApp.
I initialize the Firebase before use it. Like this:
void main() async {
print('-- main');
WidgetsFlutterBinding.ensureInitialized();
print('-- WidgetsFlutterBinding.ensureInitialized');
await Firebase.initializeApp();
print('-- main: Firebase.initializeApp');
runApp(const MyApp());
}
This is what I see in the console output:
Xcode build done. 132.9s
flutter: -- main
flutter: -- WidgetsFlutterBinding.ensureInitialized
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.
Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.
I can't see the -- main: Firebase.initializeApp line in the console. So it fails in first trying to initialize the Firebase.
I create Android/Apple apps in Firebase. Downloaded google-services.json / GoogleService-Info.plist and put in the project.
GoogleService-Info.plist:
google-services.json:
I'm not using the android, but I added dependency into build.gradle: classpath 'com.google.gms:google-services:4.3.10'
And app/build.gradle: apply plugin: 'com.google.gms.google-services'
dependencies:
firebase_auth: ^3.3.5
firebase_messaging: ^10.0.9
google_sign_in: ^5.2.1
flutter --version:
Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 18116933e7 (3 months ago) • 2021-10-15 10:46:35 -0700
Engine • revision d3ea636dc5
Tools • Dart 2.14.4
How can I solve this problem? BTW, I'm working on a brand new flutter project.
When you add google-services.json to an iOS project, you need to add it using Xcode as described in the following document:
https://firebase.flutter.dev/docs/manual-installation/ios
If you read through the page, you'll find the following note:
adding [google-service.json] manually via the filesystem won't link the file to the project
You need to try that then restart your app (rebuild it).
Edit: Additional Note:
You'll also need to add firebase_core to your dependencies in pubspec.yaml.
You have to add the GoogleService-Info.plist in Xcode instead of just placing it into the folder:
So it looks like this:
Note: The file can also be moved to a sub folder in the project (i.e. Runner).
Source: https://www.kindacode.com/article/flutter-correctly-adding-googleservices-info-plist-to-ios/
Here's how I fixed this error:
Ensure that all firebase services have been added to your pubspec.yaml file, in the dependencies section. firebase_core appears to be missing and is required to connect your flutter app to your firebase project.
You can simply add it using this command:
flutter pub add firebase_core
Add the firebase plugins to your main file:
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
Replace your void main function with an asynchronous one:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const YourAppGoesHere());
}
When I add the GoogleService-Info.plist file in Xcode, I used the wrong name GoogleService-Info**(1)**.plist.
If you have the same file in downloads, mac adds a number of copy to the next downloaded file.

/src/firebase.js Module not found: Can't resolve 'firebase' in '/Users/anujgoyal/Desktop/reels/src'\?

image of the project and files
I am trying to import firebase in my react app, using the following syntax:
import firebase from "firebase";
But I am facing following issue:
./src/firebase.js
Module not found: Can't resolve 'firebase' in '/Users/Desktop/reels/src'
commands i have ran on terminal:
npm i firebase
Also i have checked in the node modules firebase was there.
You should try this code
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
I think you're using the ^9 version, so try this:
import firebase from 'firebase/compat/app'

Firebase UserCredential and initializeApp error in my flutter app

Am having this problem in my app where UserCredential is showing an error like this
I have firebase_auth installed already in my pubspec.yaml file and imported import 'package:firebase_auth/firebase_auth.dart'; but it still keeps throwing this error and the same happen to my await Firebase.initializeApp(); in main.dart. I don't know where this issue is coming from, I even upgraded my flutter to flutter 2.0 and it still persist.
Pubspec.yaml
dependencies:
google_sign_in: ^5.0.0
firebase_auth:
provider: ^5.0.0
flutter_switch: ^0.2.0
shared_preferences: ^0.5.12+4
image_picker: ^0.6.7+17
flutter_image_compress: ^0.7.0
cached_network_image: ^2.5.0
image_cropper: ^1.3.1
intl: ^0.17.0
http: ^0.12.2
transparent_image: ^1.0.0
animations: ^2.0.0
smooth_star_rating: ^1.1.1
csc_picker: ^0.0.4
flutter:
sdk: flutter
Please is there something am missing because it was working yesterday but today it isn't even after created a new folder and moving everything to it. Please help and if you need more explanation you can ask.
Try adding firebase_core as dependency. As all the firebase product depends on it.

The method 'toRawHandle' was called on null but I'm not using FirebaseMessaging

I got an exception in object_patch.dart, located in /Users/ME/development/flutter/bin/cache/dart-sdk/lib/_internal/vm/lib
The method 'toRawHandle' was called on null
I have followed the instructions here which was mentioned as a solution to related kind of problem from the post here.
Moreover, all the posts I found on this topic are related to FirebaseMessaging.
But I'm not using FirebaseMessaging.
Here is the Firebase dependencies in my pubspec.yaml:
firebase_core: ^0.5.3
firebase_auth: ^0.18.4
cloud_firestore: ^0.14.4
firebase_storage: ^5.2.0
firebase_database: ^4.4.0
cloud_functions: ^0.7.2
And my main.dart:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
Anyone knows what I might be missing?
Note: This only happens in Visual Studio Code (now version 1.51.1).
However, this problem does not happen in Android Studio (now version 4.1.1).

Resources