Firebase 未在 flutter 应用程序中初始化。它显示未找到类型“PigeonInitializeResponse”

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

我试图将 Flutter 中的 firebase 与 FlutterFire 集成。 我已经完成了文档中的很多步骤,但我无法启动该应用程序。

我尝试在 StackOverflow 上搜索错误,但找不到任何解决方案的提示。 我到底错过了什么?

c:\drumkiller\google_maps_in_flutter>flutterfire configure
i Found 3 Firebase projects.
✔ Select a Firebase project to configure your Flutter application with · g-map-8f66c (g-map)
✔ Which platforms should your configuration support (use arrow keys & space to select)? · android, ios, macos, web
i Firebase android app com.example.google_maps_in_flutter is not registered on Firebase project g-map-8f66c.
i Registered a new Firebase android app on Firebase project g-map-8f66c.
i Firebase ios app com.example.googleMapsInFlutter is not registered on Firebase project g-map-8f66c.
i Registered a new Firebase ios app on Firebase project g-map-8f66c.
i Firebase macos app com.example.googleMapsInFlutter registered.
i Firebase web app google_maps_in_flutter (web) is not registered on Firebase project g-map-8f66c.
i Registered a new Firebase web app on Firebase project g-map-8f66c.

Firebase configuration file lib\firebase_options.dart generated successfully with the following Firebase apps:

Platform  Firebase App Id
web       1:178984749635:web:3e7e105df5e73d519da2f6
android   1:178984749635:android:2c82e4a8770b873e9da2f6
ios       1:178984749635:ios:07715f151dbe0db39da2f6
macos     1:178984749635:ios:07715f151dbe0db39da2f6

Learn more about using this file and next steps from the documentation:
 > https://firebase.google.com/docs/flutter/setup

c:\drumkiller\google_maps_in_flutter>

然后生成了一些文件。然后在我的main.dart中

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_in_flutter/firebase_options.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

运行时显示的错误:flutter run 是

Launching lib\main.dart on M2101K7AG in debug mode...
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/method_channel/method_channel_firebase.dart:40:38: Error: Type 'PigeonInitializeResponse' not found.
  void _initializeFirebaseAppFromMap(PigeonInitializeResponse response) {
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/mocks.dart:5:10: Error: Type 'PigeonInitializeResponse' not found.
  Future<PigeonInitializeResponse> initializeApp(
         ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/mocks.dart:22:15: Error: Type 'PigeonInitializeResponse' not found.
  Future<List<PigeonInitializeResponse?>> initializeCore() async {
              ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/test_api.dart:47:10: Error: Type 'PigeonInitializeResponse' not found.
  Future<PigeonInitializeResponse> initializeApp(
         ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/test_api.dart:49:15: Error: Type 'PigeonInitializeResponse' not found.
  Future<List<PigeonInitializeResponse?>> initializeCore();
              ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/method_channel/method_channel_firebase.dart:29:10: Error: 'PigeonInitializeResponse' isn't a type.
    List<PigeonInitializeResponse?> apps = await api.initializeCore();
         ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/method_channel/method_channel_firebase.dart:33:15: Error: 'PigeonInitializeResponse' isn't a type.
        .cast<PigeonInitializeResponse>()
              ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/method_channel/method_channel_firebase.dart:40:38: Error: 'PigeonInitializeResponse' isn't a type.
  void _initializeFirebaseAppFromMap(PigeonInitializeResponse response) {
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/mocks.dart:9:12: Error: The method 
'PigeonInitializeResponse' isn't defined for the class 'MockFirebaseApp'.
 - 'MockFirebaseApp' is from 'package:firebase_core_platform_interface/src/pigeon/mocks.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/mocks.dart').
Try correcting the name to the name of an existing method, or defining a method named 'PigeonInitializeResponse'.
    return PigeonInitializeResponse(
           ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/mocks.dart:24:7: Error: The method 
'PigeonInitializeResponse' isn't defined for the class 'MockFirebaseApp'.
 - 'MockFirebaseApp' is from 'package:firebase_core_platform_interface/src/pigeon/mocks.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/mocks.dart').
Try correcting the name to the name of an existing method, or defining a method named 'PigeonInitializeResponse'.
      PigeonInitializeResponse(
      ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/test_api.dart:21:25: Error: 'PigeonInitializeResponse' isn't a type.
    } else if (value is PigeonInitializeResponse) {
                        ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/test_api.dart:36:16: Error: The getter 'PigeonInitializeResponse' isn't defined for the class '_TestFirebaseCoreHostApiCodec'.
 - '_TestFirebaseCoreHostApiCodec' is from 'package:firebase_core_platform_interface/src/pigeon/test_api.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/test_api.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'PigeonInitializeResponse'.
        return PigeonInitializeResponse.decode(readValue(buffer)!);
               ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/test_api.dart:71:17: Error: 'PigeonInitializeResponse' isn't a type.
          final PigeonInitializeResponse output =
                ^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.5.1/lib/src/pigeon/test_api.dart:86:22: Error: 'PigeonInitializeResponse' isn't a type.
          final List<PigeonInitializeResponse?> output =
                     ^^^^^^^^^^^^^^^^^^^^^^^^


FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1159

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 24s
Running Gradle task 'assembleDebug'...                             25.5s
Exception: Gradle task assembleDebug failed with exit code 1

添加的文件屏幕截图:

enter image description here

错误屏幕截图:

enter image description here

我的 pubspec.yaml

enter image description here

我的扑动医生:::

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.19043.2130], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.2)
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.72.2)
[√] Connected device (4 available)
[√] HTTP Host Availability

• No issues found!

我所做的是:

 1. Created a flutter Project in firebase console
 2. Set upped the flutter Fire
 3. created a new flutter project
 4. ran flutterfire configure in terminal
 5. added firebase_core in pubspec.yaml
 6. added  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,
); inside main.dart
 7. ran flutter run
android flutter firebase google-cloud-firestore firebase-authentication
3个回答
1
投票

因此,在查看了最重要的事情(即 flutterFire 的文档)之后,我发现了我所做的错误是什么。

我缺少的是:

flutterfire 配置

添加firebase服务后,必须运行flutterfire configure

所以一旦我运行了 flutterfire configure 一切就开始工作了。

enter image description here

上面屏幕截图中的注释部分对我很有帮助。

了解更多:CLI |扑火


0
投票

我无法重现它,但是 你可以尝试一下吗

仅等待 Firebase.initializeApp();


0
投票
转换此:

UserCredential userCredential = 等待 FirebaseAuth.instance.signInAnonymously();

进入此:

尝试{ 等待 FirebaseAuth.instance.signInWithCredential(credential); } 捕获 (e) { print("Google 登录时出错:$e"); EasyLoading.dismiss(); }

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