【问题标题】:Unhandled Exception: PlatformException(firebase_core, Can't create handler inside thread Thread that has not called Looper.prepare(), null, null)未处理的异常:PlatformException(firebase_core,无法在未调用 Looper.prepare() 的线程内创建处理程序,null,null)
【发布时间】:2022-01-13 14:04:02
【问题描述】:

我正在使用:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
 
  runApp(...);
}

在 Android 上运行应用程序时,我收到以下错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] 未处理的异常:PlatformException(firebase_core, Can't create handler inside thread Thread[pool-3-thread-1,5,main] 没有调用 Looper.prepare(), null, null)

我正在使用firebase_in_app_messaging: ^0.6.0+6。上面的代码适用于删除这个包。

如果我删除 await 关键字,代码运行成功,但这是一个错误还是我做错了?

【问题讨论】:

    标签: firebase flutter firebase-in-app-messaging


    【解决方案1】:

    如果添加 Future 会怎样?

    Future<void> main() async {
      WidgetsFlutterBinding.ensureInitialized();
       await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform);
    runApp(...); ,}
    

    【讨论】:

    • 抱歉,没用。
    猜你喜欢
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多