未处理异常:PlatformException(null-error,主机平台返回非空返回值的空值., null, nu



你好,我希望你很好,我有以下问题,当我在flutter中运行我的应用程序时,我得到以下错误:E/flutter (6922): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)]未处理异常:PlatformException(null- ERROR,主机平台为非空返回值返回空值。, null, null),因为我正在使用firebase,但我已经搜索了很多,事实是,提出的解决方案对我不起作用,或者我不知道是否是我错误地实现了它,很快我将向您展示代码,非常感谢您停止阅读此出版物。我还忘了说我正在写visual studio代码

主代码()


import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'src/Base/Views/BaseView.dart';
import 'src/Feactures/Presentation/Shared/StateProviders/LoadingStateProvider.dart';
import 'src/Feactures/Presentation/Shared/StateProviders/UserStateProvider.dart';
import 'src/Colors/colors.dart';
import 'src/Routes/routes.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:firebase_core/firebase_core.dart';
void main() => runApp(AppState());
class AppState extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => LoadingStateProvider()),
ChangeNotifierProvider(create: (_) => UserStateProvider())
],
child: MyAppUserState(),
);
}
}
class MyAppUserState extends StatelessWidget with BaseView {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: coordinator.start(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return MyApp(initialRoute: snapshot.data);
} else {
return CircularProgressIndicator();
}
});
}
}
class MyApp extends StatelessWidget {
final String _initialRoute;
MyApp({required String initialRoute}) : _initialRoute = initialRoute;
@override
Widget build(BuildContext context) {
Firebase.initializeApp();
return MaterialApp(
debugShowCheckedModeBanner: false,
routes: routes,
initialRoute: _initialRoute,
theme: ThemeData(
scaffoldBackgroundColor: Colors.white,
primaryColor: orange,
appBarTheme:
const AppBarTheme(iconTheme: IconThemeData(color: Colors.black))),
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en', ''), // English, no country code
Locale('es', ''), // Spanish, no country code
],
);
}
}

I really expected the app to run fine but it sends that error

您可能不想在构建方法中初始化Firebase。试着这样做(在FlutterFire文档中):

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp();
}
  1. 在pubspec.yaml中添加以下最新/最新版本的插件:firebase_core :recent version

  2. 请在main中做以下更改。飞镖文件。

希望它能工作!

import 'package:firebase_core/firebase_core.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(AppState());
}

相关内容

  • 没有找到相关文章

最新更新