我正在开发一个 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)
尝试此选项而不是
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
。