Flutter can't install firebase onto macOS - firebase

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!

Related

How to add Firebase SDK version 9 to a Service Worker Chrome Extension Manifest Version MV3?

I found this video How to add Firebase to a Service Worker - Chrome Extension Manifest Version MV3 created at 26 Jan 2021
Importing the files in the same way he did in the video I got the following error:
"SyntaxError: Unexpected token 'export'"
To try solve this I changed manifest.json to include "type"="module" (because firebase SDK version 9 uses es module)
"background": {
"service_worker": "firebase.js",
"type": "module"
},
And now the error is:
"importScripts() of new scripts after service worker installation is not allowed"
So I dowloaded to the extension https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js to include Firebase static js files in the extension in a folder called firebase and try to import as follows.
import * as firebase from "../firebase/firebase-app.js";
...
firebase.initializeApp(firebaseConfig);
Also tried:
import { initializeApp } from "../firebase/firebase-app.js";
...
initializeApp(firebaseConfig);
But in both cases I get the following errors:
FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
DevTools failed to load source map: Could not load content for chrome-extension://hoopapahcqwsdaerotpablmamhgdbhga/firebase/firebase-app.js.map: System error: net::ERR_FILE_NOT_FOUND
Any advice?
I think I found the solution to the issue, at the end of firebase-app.js is the following:
//# sourceMappingURL=firebase-app.js.map
So I went to https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js.map and copy its content in a file named firebase-app.js.map and place it in the same folder that firebase-app.js and now the code works ok.

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.

Undefined name "Firebase" following "FlutterFire Overview" tutorial

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

Vuejs2 firebase with electron error

I have configured electron with vuejs and i would like to add firebae to my project so i have
In my main.js
import * as firebase from 'firebase'
let firebasconfig = {
//config from firebase project
};
Vue.prototype.$firebase = firebase.initializeApp(firebasconfig);
But now am getting an error
Error: Failed to load gRPC binary module because it was not installed
for the current system
Expected directory: electron-v1.8-linux-x64-glibc
Found: [node-v59-linux-x64-glibc]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module
I have tried running rebuild but still fails
What elese do i need to do for this to work
I encouter the same issue with
vue-electron 1.0.6
firebase 5.4.2
vuefire 1.4.5
node 6.10.3
The following manipulation has worked for me. I have downgraded :
firebase to 4.6.0
vuefire to 1.4.4
Then ran npm rebuild and yarn and now it works.
I'm not sure all the things I have done are necessary. But for sure it looks like a problem with firebase.

The Target URI doesn't Exist:'package:firebase_database/firebase_database.dart';

Importing Dependencies in Pubsec.Yaml is successfull,
But when opening main.dart file it shows the error
Problem(1)
The Target URI doesn't Exist:
'package:firebase_database/firebase_database.dart';
Either
flutter packages get
needs to be run or failed when you run it
or you just need to restart your IDE. I saw it mentioned a few times recently that this was necessary to fix the problem.
1- Go to the link: https://pub.dev/packages/firebase_database#-installing-tab-
2- Add dependencies in pubspec.yaml file.e.g:-
dependencies:
flutter:
sdk: flutter
firebase_database: ^3.1.3
3- Press ctrl+s after two seconds it will give a message click on Get Dependencies, and wait for some time its will run pub get in your project.
4- Problem will be solved.

Resources