错误:无法在“ServicesBinding?”上访问属性“defaultBinaryMessenger”因为它可能为空

时间:2021-06-14 15:13:13

标签: flutter

我正在尝试使用颤振做一个简单的 firebase 应用程序。我还没有启动 firebase 代码。刚刚添加了 Firebase.initializeApp()。运行时出现以下异常,程序停止。

/C:/src/flutter/packages/flutter/lib/src/services/platform_channel.dart:148:52: Error: Property 'defaultBinaryMessenger' cannot be accessed on 'ServicesBinding?' because it is potentially null.
 - 'ServicesBinding' is from 'package:flutter/src/services/binding.dart' ('/C:/src/flutter/packages/flutter/lib/src/services/binding.dart').
Try accessing using ?. instead.
      _binaryMessenger ?? ServicesBinding.instance.defaultBinaryMessenger;

以下是我的 main.dart 代码:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(new MaterialApp(
    home: Login(),
  ));
}

0 个答案:

没有答案