简体   繁体   English

Flutter / Firebase 项目 - 是“未处理的异常:Null 检查运算符在 Z37A625 上使用导致66489C1DAE2997 值?

[英]Flutter / Firebase project - Is `Unhandled Exception: Null check operator used on a null value` causing a blank screen?

I'm working on a flutter project with firebase.我正在使用 firebase 进行 flutter 项目。 I'm currently developing on a MacBook, using a simulated iPhone (just in case this is relevant).我目前正在使用模拟 iPhone 在 MacBook 上进行开发(以防万一)。 I am able to run my app, but when doing so it's just a white blank screen that never goes away, it may also be pertinent to know this happens on the Chrome, and simulated Android devices too.我可以运行我的应用程序,但是这样做时它只是一个永远不会消失的白色空白屏幕,知道这也可能发生在 Chrome 和模拟 Android 设备上也可能是相关的。 Looking in the run window, I can see I have an error showing the following:run window 中查看,我可以看到出现以下错误:

Launching lib/main.dart on iPhone 13 in debug mode...
Running Xcode build...
Xcode build done.                                           28.4s
Debug service listening on ws://127.0.0.1:61474/fF4XR-ozS5s=/ws
Syncing files to device iPhone 13...
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
#0      MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:121:86)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:146:36)
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:342:41)
#4      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:31:37)
#5      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73:13)
#6      Firebase.initializeApp (package:firebase_core/src/firebase.dart:42:47)
#7      main (package:we_rise/main.dart:8:18)
#8      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:145:25)
#9      _rootRun (dart:async/zon<…>

Since I'm still quite a novice, I can't quite decipher what has gone wrong, or what I'm looking at here.由于我还是个新手,所以我无法完全理解出了什么问题,或者我在这里看到了什么。 Please find below my main.dart file code:请在下面找到我的main.dart文件代码:

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'database_config.dart';
import 'launch_page.dart';

void main() async {
  await Firebase.initializeApp(
    options: FirebaseOptions(
        apiKey: "foo",//"apiKey",
        appId: "foo",//"appId",
        messagingSenderId: "foo",//"messagingSenderId",
        projectId: "foo"),//"projectId"),
  );
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown],
    );
    return MaterialApp(
      theme: ThemeData(
        brightness: Brightness.light,
        fontFamily: 'BookmanOldStyle',
      ),
      home: LaunchPage(),
    );
  }
}

I hope this is useful.我希望这很有用。 I truly do not understand why it's presenting me with a blank white screen when the app loads.我真的不明白为什么当应用程序加载时它会给我一个空白的白屏。 I also read this answer , but I don't think I've used a null check operator in my code.我也阅读了这个答案,但我认为我没有在我的代码中使用 null 检查运算符。 Any help, advice, and criticism is appreciated.感谢任何帮助、建议和批评。

EDIT: ADDED FLUTTER DOCTOR OUTPUT编辑:添加 FLUTTER 医生 OUTPUT

flutter doctor output: flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Connected device (2 available)

• No issues found!

flutter doctor -v output: flutter doctor -v output:

flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
    • Flutter version 2.5.3 at /Users/me/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (3 months ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/me/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.2.1, Build version 13C100
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] Connected device (2 available)
    • iPhone 13 (mobile) • C0D4EC95-07AF-46AB-A35E-F2B9F4437875 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 97.0.4692.71

• No issues found!

I think one of these should work.我认为其中之一应该有效。

  1. Make sure you have initialized firebase properly ie right steps taken to integrate firebase with your project.确保您已正确初始化 firebase,即采取正确的步骤将 firebase 与您的项目集成。

  2. Add a name in the Firebase.initializeApp-在 Firebase.initializeApp 中添加名称

` await Firebase.initializeApp( ` 等待 Firebase.initializeApp(

name: "SecondaryApp",//**Add this line**
options: FirebaseOptions(
    apiKey: "foo",//"apiKey",
    appId: "foo",//"appId",
    messagingSenderId: "foo",//"messagingSenderId",
    projectId: "foo"),

);` );`

Can you show 'database_config.dart' file, also no need to include firebase options for mobile as they are already included in json files.你能显示'database_config.dart'文件吗,也不需要包括移动设备的firebase选项,因为它们已经包含在json文件中。

You should add the你应该添加

WidgetsFlutterBinding.ensureInitialized() WidgetsFlutterBinding.ensureInitialized()

to the main function before Firebase initialization.到 Firebase 初始化之前的主 function。

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: FirebaseOptions(
        apiKey: "foo",//"apiKey",
        appId: "foo",//"appId",
        messagingSenderId: "foo",//"messagingSenderId",
        projectId: "foo"),//"projectId"),
  );
  await DatabaseConfig.initFirebase();
  runApp(MyApp());
}

For good measure, try a "flutter upgrade", since 2.5.3 is no longer the latest stable version, they're on 2.8.1 now.为了更好的衡量,尝试“flutter upgrade”,因为 2.5.3 不再是最新的稳定版本,他们现在在 2.8.1 上。 Then make sure you followed all of the instructions (to the letter) under each of the platform setup sections listed here.然后确保您遵循此处列出的每个平台设置部分下的所有说明(按字母顺序)。

If you've had to run "flutter clean" at any point or deleted your build folders, make sure you check them for the required includes as specified in that link above.如果您不得不在任何时候运行“flutter clean”或删除了您的构建文件夹,请确保检查它们以获取上面该链接中指定的所需包含。 I saw in the original post you said that flutterfire was not working on any of your platforms, which to me indicates that the library might not be fully configured under the build folders for each platform.我在原始帖子中看到您说flutterfire 无法在您的任何平台上运行,这对我来说表明该库可能未在每个平台的构建文件夹下完全配置。

To all those who come across this issue, what worked for me was creating a new project on the Windows version (I'm using android studio) and remaking the program on there, you can even copy and paste for the most part.对于所有遇到此问题的人,对我有用的是在 Windows 版本(我使用 android 工作室)上创建一个新项目并在那里重新制作程序,您甚至可以复制和粘贴大部分内容。

It seems to me that the main issue was that I do not own an iPhone while developing on MacOS, and consequently, I was unable to run this while it's linked to my developer profile.在我看来,主要问题是我在 MacOS 上开发时没有 iPhone,因此,当它链接到我的开发人员资料时,我无法运行它。

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

相关问题 未处理的异常:未处理的错误 Null 检查运算符用于 flutter 中的“AuthBloc”实例中的 null 值 - Unhandled Exception: Unhandled error Null check operator used on a null value occurred in Instance of 'AuthBloc' in flutter 未处理的异常:Null 检查在 null 值上使用的运算符...Null dart 中的安全性 - Unhandled Exception: Null check operator used on a null value...Null Safety in dart 颤振:在空值上使用空检查运算符? - flutter: Null check operator used on a null value? Flutter 中的“用于 Null 值的 Null 检查运算符” - "Null check operator used on a Null Value" in Flutter Null 检查运算符用于 null 值 Flutter - Null check operator used on a null value Flutter Null 检查运算符用于 flutter 的 null 值 - Null check operator used on a null value for flutter Flutter 显示的 formkey 异常 _CastError(在 null 值上使用了 Null 检查运算符) - Flutter formkey exception displayed _CastError (Null check operator used on a null value) Null 检查运算符用于 Flutter 2.5.3 上的 null 值 - Null check operator used on a null value on Flutter 2.5.3 Null 检查运算符用于 null 值 FLUTTER 2.10 - Null check operator used on a null value FLUTTER 2.10 Flutter - _CastError(在 null 值上使用空检查运算符) - Flutter - _CastError (Null check operator used on a null value)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM