而在调试模式下不出现

而在调试模式下不出现

本文介绍了错误仅在发布模式下出现,而在调试模式下不出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切在调试模式下都可以正常工作,但是当我在发布模式下运行应用程序时,它会显示以下屏幕:

Everything is working fine in debug mode but when I run the application in release mode, it produces this screen:

,当我尝试在Firebase上托管应用程序时,出现以下屏幕:

and when I try hosting the application on firebase, I get this screen:

我不确定如何处理此错误,因为有关此问题的信息不多.但是基于无Firebase应用"错误,我认为该错误可能出在我的main.dart中.

I am not sure how to handle this error as there is not much info on this issue. But based on the "No firebase app" error, i think that the error might be in my main.dart.

void main() {
  assert(() {
    fb.initializeApp(
      apiKey: "",
      authDomain: "",
      databaseURL: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: "",
    );

    return true;
  }());

  WidgetsFlutterBinding.ensureInitialized();
  BlocSupervisor.delegate = GeneralBlocDelegate();

  runApp(MultiRepositoryProvider(
      providers: [
        RepositoryProvider<UserRepository>(
            builder: (context) => UserRepository()),
      ],
      child: MultiBlocProvider(providers: [
        BlocProvider<AuthBloc>(
          builder: (context) => AuthBloc(
              userRepository: RepositoryProvider.of<UserRepository>(context))
            ..add(AppStarted()),
        ),
      ], child: App())));
}

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>my website</title>
</head>
<body>
  <script src="main.dart.js" type="application/javascript"></script>

  <script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-firestore.js"></script>

  <script src="/__/firebase/7.2.2/firebase-app.js"></script>
  <script src="/__/firebase/7.2.2/firebase-auth.js"></script>
  <script src="/__/firebase/7.2.2/firebase-firestore.js"></script>
  <script src="/__/firebase/init.js"></script>

</body>
</html>

pubspec.yaml

description: A new Flutter project.
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2

  firebase: ^6.0.0
  flutter_bloc: ^1.0.0
  equatable: ^0.6.1
  font_awesome_flutter: ^8.5.0

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - assets/images/

推荐答案

问题1:使用assert()函数初始化应用

Problem 1: Using assert() function to initialize app

您正在assert()方法内部调用fb.initializeApp()方法,在发行版本中将不会调用该方法. assert方法在开发过程中非常有用,可以添加一些其他检查.它不应包含或用于处理任何功能/业务逻辑.查看飞镖语言之旅的部分.它指出断言方法在生产模式下将被忽略.

You are calling the fb.initializeApp() method inside the assert() method which will not be called in the release build. assert method is useful during development to add some additional checks. It should not contain or be used to handle, any functional/business logic. Check this section of the dart language tour. It states that assert method is ignored in production mode.

问题2:pupspec.yaml

Problem 2: Missing asset information in pupspec.yaml

在您的index.html中,我看到您正在尝试加载某些.js文件,例如/__/firebase/init.js. Flutter构建不会将其保留在build文件夹中,除非您将其标记为pubspec.yaml中的资产.

In your index.html I see you are trying to load some .js files like this /__/firebase/init.js. Flutter build will not keep this in the build folder unless you mark it as an asset in your pubspec.yaml.

假设您将应用程序所需的所有.js文件放置在名为/js/init.js的文件夹中,如下所示.

Assuming you placed all your .js files you need for your application in a folder named /js/init.js like the following.

您的pubspec.yaml中需要一个这样的条目.

You need an entry like this in your pubspec.yaml.

assets:
  - js/init.js
  - js/firebase-app.js

OR 只需像这样包含整个文件夹即可.

ORJust include the entire folder like this.

assets:
  - js/

同样适用于所有资产,例如图像,数据json等...选中此参考以获取更多详细信息.

The same applies for all the assets like images, data json etc... Check this reference for more details.

可能的问题3:在Index.html中错误地引用了本地.js文件

Possible Problem 3: Incorrectly referring local .js file in Index.html

在index.html中,您正尝试加载一些本地的.js文件,如前所述.如果您遵循我建议的文件夹结构,我认为您应该按如下所示加载这些文件.您可能应该根据自己的选择进行编辑.

In your index.html you are trying to load some local .js file as mentioned earlier. I think you should load these files as shown below if you follow my suggested folder structure. You should probably edit it based on your own choice.


<script src="assets/js/init.js" type="application/javascript"></script>

<script src="assets/js/firebase-app.js" type="application/javascript"></script>

希望他能帮上忙.开心的飘飘.

Hope his helps. Happy Fluttering.

这篇关于错误仅在发布模式下出现,而在调试模式下不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:00