Unhandled Exception: MissingPluginException(No implementation found for method DatabaseReference#set on channel plugins.flutter.io/firebase_database)

huangapple go评论64阅读模式
英文:

Unhandled Exception: MissingPluginException(No implementation found for method DatabaseReference#set on channel plugins.flutter.io/firebase_database)

问题

我遇到了一个错误:Unhandled Exception: MissingPluginException(No implementation found for method DatabaseReference#set on channel plugins.flutter.io/firebase_database)。我该如何修复这个错误?我试图在实时数据库中设置一个整数,但在点击时出现了这个错误。有人知道我做错了什么以及如何修复它。

主页面上初始化 Firebase 的代码如下:

Future main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

以及 initState 代码如下:

@override
void initState() {
  super.initState();
  Firebase.initializeApp();
  _checkFirstTime();
}

请问有人可以帮助我解决这个问题吗?我已经使用 CLI 将应用程序连接到 Firebase。

英文:

I get the error Unhandled Exception: MissingPluginException(No implementation found for method DatabaseReference#set on channel plugins.flutter.io/firebase_database) how can i fix this error? I am trying to set an int in the realtime database but i get this error onclick, does anyone know what i did wrong and how to fix it.

                children: [
                  Container(
                    margin: EdgeInsets.only(right: 5),
                    child: ImageIcon(AssetImage("assets/icons8-money-50.png"),),),

                  Text('$money', style: TextStyle(color: Colors.purple.shade900)),
                  SizedBox(width: 10),
                  Padding(padding: EdgeInsets.fromLTRB(0, 0, 8, 0),
                child:TextButton(
                    child: Text("Buy Credits"),
                    onPressed: () async {

                     fetchOffers(context);
                     DatabaseReference ref = FirebaseDatabase.instance.ref("users/123");
                     await ref.set({
                       "Credits": 10,
                     });
                    },
                  ))
                ],
              ),

The main page where i initialized firebase:

Future main() async{

  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
  );


  runApp( MyApp());
}

And the initstate:

  void initState() {
    super.initState();
    Firebase.initializeApp();
    _checkFirstTime();
  }

Can anyone pleas help me with this problem. I have used the Cli to link the app to Firebase.

答案1

得分: 0

重启 Android Studio,然后它就会正常工作。

英文:

Restart Android studio, then it will work.

huangapple
  • 本文由 发表于 2023年2月16日 03:51:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464813.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定