I would like to use a Firebase Database in Flutter, but while the authentification is working, I get an error for the Firebase Database .
I am initializing the app with
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// I also found this version: FirebaseDatabase database = FirebaseDatabase.instance;
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform
);
FirebaseFirestore.instance.settings = const Settings(
persistenceEnabled: true,
);
FirebaseUIAuth.configureProviders([
EmailAuthProvider(),
...
]);
runApp(
ChangeNotifierProvider(
create : (context) => MyState(),
child : MaterialApp(
...
home: MainPage()),
)
);
}
and following this tutorial, I would like to read and write the database in any widget by initializing
DatabaseReference ref = FirebaseDatabase.instance.ref("users/123");
and using it in the build method like
await ref.set({
"name": "John",
"age": 18,
"address": {
"line1": "100 Mountain View"
}
});
but I get the error
The following NativeError object was thrown building SomeWidget(state: _SomeWidgetState#87613):
Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://.firebaseio.com
Where do you find this url, where do you initialize this in the app?
- firebase_database: ^11.3.5
- cloud_firestore: ^5.6.5
- cloud_firestore: ^5.6.5
flutterfireCLI as shown here:firebase.google.com/docs/flutter/…? --- Also: note that Firestore and Firebase (Realtime) Database are completely separate products. While both part of Firebase, they are completely separate and the SDKs and APIs for one, won't work with the other. Your code tries to use the Realtime Database, not Firestore - so if you're actually trying to use Firestore, you'll want to reread that documentation for code samples.