Flutter 错误:未处理的异常:PlatformException(通道错误,无法在通道上建立连接。)

问题描述 投票:0回答:1

我正在开发一个 Flutter 项目。我已经被这个错误困扰了 72 小时。有人可以帮我吗?这是我的 main.dart 文件。

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

运行时,这是我收到的错误: 错误:flutter/runtime/dart_vm_initializer.cc(41)] 未处理的异常:PlatformException(通道错误,无法在通道上建立连接。,null,null)

flutter
1个回答
0
投票

尝试此选项而不是

DefaultFirebaseOptions.currentPlatform

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: const FirebaseOptions(
      apiKey: "project apikey",
      appId: "project appId",
      messagingSenderId: "project messagingSenderId",
      projectId: "projectId",
    ),
  );
  runApp(const MyApp());
}

您可以从 firebase 的设置

apiKey
中找到您的
appId
messagingSenderId
ProjectId
Project settings/General

© www.soinside.com 2019 - 2024. All rights reserved.