5

I have looked at Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com but database url is not firebaseio.com expo and I don't believe it applies.

So...Im using flutter on the web FYI and testing in chrome.

In my main.dart I use:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
  );
  setupDependencies();
  runApp(const MyApp());
}

And doing this did eliminate some errors, but not all errors.

Also, in another file I have a global var:

final DatabaseReference kDatabase = FirebaseDatabase.instance.ref();

And when trying to use kDatabase to operate on firebase, I get

Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR
FIREBASE>.firebaseio.com

I have done dart pub get firebase ..and it says it is up to date.

My firebase_options.dart was generated automatically from the firebase website.

relevant pub spec:

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.3
  dartz: ^0.10.0
  get_it: ^7.2.0
  
  freezed_annotation: ^1.1.0
  cached_network_image: ^3.1.0
  provider: ^6.0.1
  firebase_auth: ^3.1.3
  firebase_database: ^9.0.3
  firebase_analytics: ^9.0.3
  firebase_storage: ^10.0.5 
  firebase_messaging: ^11.2.3
  firebase_remote_config: ^2.0.2
  firebase_dynamic_links: ^4.0.2
  cloud_firestore: ^3.1.4

Any ideas?

3
  • Seems like you should declare database config if you want to use it no? Or if it gets generated, what does it look like? Commented Mar 4, 2022 at 23:59
  • @html_programmer I'm a complete n00b to flutter, can you point me in right direction to this config? Thank you 🙌 Commented Mar 5, 2022 at 0:00
  • Well no, I don't use Flutter LOL! But in order to connect to a db, you need a connection, just makes sense. This is probably what the url is referring to. This should be mentioned in the docs somewhere of whatever package you're using, and probably you should find the db connection string somewhere on your Firebase account I assume. Or perhaps you can generate some config file, I dunno. It's always sort of the same thing this kind of actions. Commented Mar 5, 2022 at 0:04

4 Answers 4

3

If you have used $ flutterfire configure to configure firebase to your flutter project as shown in here before adding Realtime Database, you will have to run the command again to reconfigure your project or add "databaseURL" to the FirebaseOptions in your lib/firebase_options.dart.

Your lib/firebase_options.dart should look something like this:

// inside lib/firebase_options.dart

// ...

static const FirebaseOptions web = FirebaseOptions(
    apiKey: '...',
    appId: '...',
    messagingSenderId: '...',
    projectId: 'project-id',
    authDomain: 'project-id.firebaseapp.com',
    databaseURL: 'https://your-database-id.firebasedatabase.app', // IMPORTANT!
    storageBucket: 'project-id.appspot.com',
    measurementId: '...',
);

// ...
Sign up to request clarification or add additional context in comments.

Comments

0

I my case I forgot to add Database URL which you will get in Firebase Console -> Project Settings-> Your Apps-> Select your app.

Comments

0

The solution is: got to your firebaseOptions

copy ( apiKey: 'AIzaSyBm70TH68natnHg_Ueq3-eKpEKHdaj0p2k',
    appId: '1:733077779058:web:9fb7ba429c9fbf03b608eb',
    messagingSenderId: '733077779058',
    projectId: 'socialmedia-9cd65',
    authDomain: 'socialmedia-9cd65.firebaseapp.com',
    storageBucket: 'socialmedia-9cd65.appspot.com',
    measurementId: 'G-LTHTMKWY94',) 

These parameters, according to your project link mac, web, android, add to these pramaters to your main file options:

FirebaseOptions(apiKey: 'AIzaSyBm70TH68natnHg_Ueq3-eKpEKHdaj0p2k',
    appId: '1:733077779058:web:9fb7ba429c9fbf03b608eb',
    messagingSenderId: '733077779058',
    projectId: 'socialmedia-9cd65',
    authDomain: 'socialmedia-9cd65.firebaseapp.com',
    storageBucket: 'socialmedia-9cd65.appspot.com',
    measurementId: 'G-LTHTMKWY94',) 

Now you only required a dataBaseUrl go to your realdata base copy the url that https://socialmedia-9cd65-default-rtdb.firebaseio.com

and then add the another parameter "databaseURL" in the above section and copy paste the url infront of "databaseURL=https://socialmedia-9cd65-default-rtdb.firebaseio.com

Now your error should b sovled

Comments

0

Edit: Check Firebase Config. I was checking the generated one, but had moved config to another file, so it wasn't working of course.

Original: I had this issue and I checked all of the firebase configuration stuff, and it was still happening. I tried FirebaseDatabase.instance.ref("url here") instead of just FirebaseDatabase.instance.ref() because I thought that would bypass whatever config stuff was wrong. It still didn't work. I thought it must be a dependency conflict so I move everything out of my project so it was just a main pulling from Realtime database. It worked, so I started slowly adding my code back to find the conflict. I never found it and its working now. This isn't a real solution, but I thought I'd share incase anyone is in my situation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.