【问题标题】:E/MethodChannel#plugins.flutter.io/firebase_database( 6299): Failed to handle method callE/MethodChannel#plugins.flutter.io/firebase_database(6299):处理方法调用失败
【发布时间】:2020-12-26 14:02:39
【问题描述】:

我正在尝试向 Firebase 数据库添加一个简单的文本。我已经使用 gmail 成功登录并且工作正常,但是当我尝试添加任何内容时,它给了我这个错误:

E/MethodChannel#plugins.flutter.io/firebase_database( 6299): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_database( 6299): com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@17.0.0:103)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@17.0.0:60)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at io.flutter.plugins.firebase.database.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:236)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/firebase_database( 6299):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/flutter ( 6299): lets gooo00000000000
E/flutter ( 6299): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call., null, com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.
E/flutter ( 6299):  at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@17.0.0:103)
E/flutter ( 6299):  at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@17.0.0:60)
E/flutter ( 6299):  at io.flutter.plugins.firebase.database.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:236)
E/flutter ( 6299):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter ( 6299):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter ( 6299):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/flutter ( 6299):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 6299):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter ( 6299):  at android.os.Looper.loop(Looper.java:160)
E/flutter ( 6299):  at android.app.ActivityThread.main(ActivityThread.java:6669)

代码:



    final databaser= FirebaseDatabase.instance.reference();
    
     savePost(){
      databaser.child('cats').set({
      'id':'1',
      'name': 'yes sirr'
      }
    );
      print("lets gooo00000000000");
    
     
    }

no caption

the error that gave me a headache

【问题讨论】:

    标签: firebase flutter firebase-realtime-database


    【解决方案1】:

    参见示例https://pub.dev/packages/firebase_database/example 我认为您必须使用 await Firebase.initializeApp(...) 进行初始化

    【讨论】:

      【解决方案2】:

      正如 spkersten 在 their answer 中所说,确保在获取数据库实例之前调用 Firebase.initializeApp(...)

      如果您已经这样做了并且仍然得到答案,则可能是您从 Firebase 控制台下载的 Google-Services.json 中缺少数据库 URL。如果是这个原因,您可以通过在确保已在控制台中创建数据库后下载更新的Google-Services.json 来解决它,然后像以前一样将其添加到您的应用中。

      有关更多信息,请参阅:

      【讨论】:

        猜你喜欢
        • 2019-10-09
        • 2021-03-18
        • 2020-12-07
        • 2020-03-31
        • 2021-01-31
        • 2018-07-06
        • 2019-04-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多