Flutter应用程序中未初始化Firebase,它显示未找到类型"PigeonInitializeResponse"

y0u0uwnf  于 2022-11-30  发布在  Flutter
关注(0)|答案(2)|浏览(87)

我试图将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>

然后生成了一些文件。然后在我的主. 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运行

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
    • 添加的文件屏幕截图:**

    • 错误屏幕截图:**

    • 我的公共规范yaml**

"我的心脏跳动医生"

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
23c0lvtd

23c0lvtd1#

我无法复制,但请尝试

等待Firebase.初始化应用程序();仅限

5anewei6

5anewei62#

因此,在经历了最重要的事情,iidoEe. flutterfire的文档之后,我发现了我所做的错误。
我错过的是:
Flutter 发射配置
添加firebase服务后,必须运行flutterfire configure
因此,一旦我运行flutterfire configure,一切都开始工作。

上面屏幕截图中的注解部分对我很有帮助。
更多信息:CLI | FlutterFire

相关问题