简体   繁体   English

为什么我在托管 Flutter 应用程序时出现灰屏?

[英]Why do I get grey screen when hosting Flutter app?

I've checked all the other answers about grey screen when hosting a web app but I have not found a solution for my problem yet.我已经检查了托管 web 应用程序时有关灰屏的所有其他答案,但我还没有找到解决我的问题的方法。 I have checked my code for errors, and fixed the ones that I had.我检查了我的代码是否有错误,并修复了我的错误。

When I deploy my app, everything seems fine.当我部署我的应用程序时,一切似乎都很好。 The loginscreen appears and I can succesfully log in and get directed to my homescreen.登录屏幕出现,我可以成功登录并转到我的主屏幕。 But when I refresh my browser the screen turns grey and I have to deploy my app again to get it to work.但是当我刷新我的浏览器时,屏幕变灰,我必须再次部署我的应用程序才能让它工作。

Hope somebody has some clue to what this can be?希望有人知道这可能是什么?

Some further testing in Debugmode get me this error:在 Debugmode 中的一些进一步测试让我得到这个错误:

The following TypeErrorImpl was thrown building Builder: Unexpected null value.生成器抛出以下 TypeErrorImpl:意外的 null 值。 The relevant error-causing widget was: MaterialApp MaterialApp:file:///C:/Users//lib/main.dart:50:12导致错误的相关小部件是:MaterialApp MaterialApp:file:///C:/Users//lib/main.dart:50:12

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SharedPreferences sharedpreference  = await SharedPreferences.getInstance();
  sharedpreference.getString('email');
  await Firebase.initializeApp( options: const FirebaseOptions(
    apiKey: "AI******YSpsnJ8",
    appId: "1:981*******50",
    messagingSenderId: "******",
    projectId: "tdfsfdf**",
  ),
  );
  if (kIsWeb) {
    print('Web');
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]
    ).then((_) => runApp(const MyApp()));
  } else {
    print('mobil');
    // NOT running on the web! You can check for additional platforms here.
    runApp(const MyApp());
}
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return MaterialApp(

      title: 'Flutter Demo',
     home: FirebaseAuth.instance.currentUser == null
          ? const UserLoginPage()
          : const UserHomePage(),
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),

      initialRoute: UserLoginPage.id,
      routes:{
        UserLoginPage.id : (context) => const UserLoginPage(),
        AdminServicePage.id : (context) => const AdminServicePage(),
        AdminToolsPage.id : (context) => const AdminToolsPage(),
        AdminDeviationPage.id : (context) => const AdminDeviationPage(),
        AdminUsersPage.id : (context) => const AdminUsersPage(),
        UserHomePage.id : (context) => const UserHomePage(),
        UserToolListPage.id : (context) => const UserToolListPage(),
        WebHomePage.id : (context) => const WebHomePage(),
        WebOverviewPage.id : (context) => const WebOverviewPage(),
       
      },
      debugShowCheckedModeBanner: false,

    );
  }
}


Without code we can not be specific to tell where the problem is没有代码,我们无法具体说明问题出在哪里

However, If you are using some libraries / packages, make sure they are supported on web as well as they are supported on Android or Ios但是,如果您使用一些库/包,请确保 web 支持它们,并且 Android 或 Ios 支持它们

If you're using firebase, make sure the project on the firebse console include web如果您使用的是 firebase,请确保 firebse 控制台上的项目包括 web

If you're no longer running your app in debug mode or on a simulator you get gray screen instead or red, which is usually called by some error.如果您不再在调试模式或模拟器上运行您的应用程序,您会看到灰屏或红色,这通常是由一些错误调用的。

To debug, I would add catcher package to catch un-handle errors.要调试,我会添加捕手 package来捕获未处理错误。 Configure the package to either save locally as text file to review later or you can have it email as it happens or choose from other options.将 package 配置为在本地保存为文本文件以供稍后查看,或者您可以将其 email (当它发生时)或从其他选项中选择。

Hope this helps!希望这可以帮助!

You have to initialize Firebase before running main void so it have to look like that:你必须在运行 main void 之前初始化 Firebase 所以它必须看起来像这样:

Future<void> main() async {
 WidgetsFlutterBinding.ensureInitialized();
 Firebase.initializeApp(
 options: FirebaseOptions(
     apiKey: Constants.apiKey,
     authDomain: Constants.authDomain,
     projectId: Constants.projectId,
     storageBucket: Constants.storageBucket,
     messagingSenderId: Constants.messagingSenderId,
     appId: Constants.appId,
     measurementId: Constants.measurementId),
 ).then((value) {
    runApp(const MyApp());
    setUrlStrategy(PathUrlStrategy());
 });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发布模式下的灰屏(IOS - Flutter) - Grey screen in release mode (IOS - Flutter) Flutter 问题:在锁屏和后台屏幕通知图标显示灰色 - Flutter problem: On lock screen and background screen notification Icon showing grey 为什么我在通过 Azure AD App-Only 授予访问权限时收到 401 Unauthorized? - Why do I get 401 Unauthorized when granting access via Azure AD App-Only? 有谁知道启动 firebase 应用程序时如何摆脱“Firebase Hosting Setup Complete”屏幕? - does anyone know how to get rid of "Firebase Hosting Setup Complete" screen when launching a firebase application? Flutter web 应用程序丢失 firebase.json 并在部署到 firebase 托管时显示“欢迎 Firebase 托管设置完成” - Flutter web app is missing firebase.json and shows "Welcome Firebase Hosting Setup Complete" when deployed to firebase hosting 为什么在 Flutter wih Firestore 中使用 foreach 方法后得到 null? - Why do i get null after using the foreach method in Flutter wih Firestore? 为什么在 S3 上上传时得到空白 pdf? - Why do I get a blank pdf when uploaded on S3? Flutter web - Firebase 云消息 - 在本地主机上运行正常,而不是当我上传到 firebase 托管 - Flutter web - Firebase cloud messaging - running OK on localhost, not when I upload to firebase hosting 我如何在收到背景 firebase 消息时启动 Flutter 应用程序,即使屏幕已锁定我也希望我的应用程序启动 - How i can make Flutter application start when it receives background firebase message even if the screen is locked i want my app to start 导航到新屏幕时更改 flutter 应用程序中的用户首选项 - Changing user preferences in a flutter app when navigating to new screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM