英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论