未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_core 上找不到方法 Firebase#initializeCore 的实
Posted
技术标签:
【中文标题】未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_core 上找不到方法 Firebase#initializeCore 的实现)【英文标题】:Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) 【发布时间】:2021-12-31 22:08:53 【问题描述】:"E/flutter (6763): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] "
这是我遇到的错误。
这是我的代码..
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'firstpage.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MaterialApp(
routes:
'/home':(context)
return Homepage();
,
'/first':(context)
return First_Page();
,
));
class Homepage extends StatefulWidget
const Homepage(Key? key) : super(key: key);
@override
_HomepageState createState() => _HomepageState();
class _HomepageState extends State<Homepage>
final Future<FirebaseApp> _initialization = Firebase.initializeApp();
final _auth= FirebaseAuth.instance;
final _user=TextEditingController();
final _pass=TextEditingController();
String email='';
String password='';
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text(
'Sign-Up',
),
centerTitle: true,
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsets.only(top: 250),
),
Container(
child: TextFormField(
controller: _user,
decoration: InputDecoration(
hintText: "Email-id",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
)
),
),
),
SizedBox(height: 10,),
Container(
child: TextFormField(
controller: _pass,
decoration: InputDecoration(
hintText: "Password",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
)
),
),
),
FlatButton(
color: Colors.blue,
child: Text('Sign-up'),
onPressed: () async
await Firebase.initializeApp();
email=_user.toString();
password=_pass.toString();
try
final newuser= await _auth.createUserWithEmailAndPassword(email: email, password:
password);
if(newuser!=null)
Navigator.pushNamed(context, '/First_Page');
catch(e)
print('error');
,
),
],
),
),
);
Here are the dependencies in my pubspec.yaml
dependencies:
flutter:
sdk: flutter
firebase_auth: ^3.2.0
firebase_core : ^1.10.0
And here are all the errors that i am getting...
E/flutter ( 6763): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
MissingPluginException(No implementation found for method Firebase#initializeCore on
channel plugins.flutter.io/firebase_core)
E/flutter ( 6763): #0 MethodChannel._invokeMethod
(package:flutter/src/services/platform_channel.dart:154:7)
E/flutter ( 6763): <asynchronous suspension>
E/flutter ( 6763): #1 MethodChannel.invokeListMethod
(package:flutter/src/services/platform_channel.dart:342:35)
E/flutter ( 6763): <asynchronous suspension>
E/flutter ( 6763): #2 MethodChannelFirebase._initializeCore
(package:firebase_core_platform_interface/src/method_channel/method_channel_
firebase.dart:31:23)
E/flutter ( 6763): <asynchronous suspension>
E/flutter ( 6763): #3 MethodChannelFirebase.initializeApp
(package:firebase_core_platform_interface/src/method_channel
/method_channel_firebase.dart:73:7)
E/flutter ( 6763): <asynchronous suspension>
E/flutter ( 6763): #4 Firebase.initializeApp
(package:firebase_core/src/firebase.dart:42:31)
E/flutter ( 6763): <asynchronous suspension>
E/flutter ( 6763): #5 main (package:firebase/main.dart:7:3)
E/flutter ( 6763): <asynchronous suspension>
E/flutter ( 6763):
成功重启我的应用程序后出现这些错误。
【问题讨论】:
你在 build.gradle 中添加了 google-services 插件吗? 是的@PeterHaddad 【参考方案1】:在 MainActivity.kt 中导入这个
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
并扩展您的课程
FlutterFragmentActivity()
然后添加
override fun configureFlutterEngine(flutterEngine: FlutterEngine)
GeneratedPluginRegistrant.registerWith(flutterEngine)
【讨论】:
以上是关于未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_core 上找不到方法 Firebase#initializeCore 的实的主要内容,如果未能解决你的问题,请参考以下文章
SQL 异常未处理 - System.Data.dll 中出现“System.Data.SqlClient.SqlException”类型的未处理异常