Firebase 登录模块中的问题无法正常登录

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

Firebase 登录模块中的问题匿名登录在模拟器中不起作用。

  1. 当我使用“await”运行代码时
  2. “等待”应用程序卡在黑屏
  3. 无需“等待”即可运行
  4. 应用程序已成功安装,但当我按访客时,它无法工作
  5. 一旦我按下客人,它就会看起来像这样 main.dart
import 'package:flutter/material.dart';
import 'package:multi_score/auth/customer_signup.dart';
import 'package:multi_score/main_screens/customer_home.dart';
import 'package:multi_score/main_screens/supplier_home.dart';
import 'package:multi_score/main_screens/welcome_screen.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  Firebase.initializeApp();
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      //home: WelcomeScreen(),
      initialRoute: '/welcome_screen',
      routes: {
        '/welcome_screen':(context) => const WelcomeScreen(),
        '/customer_home':(context) => const CustomerHomeScreen(),
        '/supplier_home':(context) => const SupplierHomeScreen(),
        '/customer_signup':(context) => const CustomerRagister(),
      },
    );
  }
}

请查找以下问题日志

Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Debug service listening on ws://127.0.0.1:53308/_gBL46eXSKI=/ws
Syncing files to device sdk gphone x86...
E/flutter ( 5501): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly., Exception, Cause: null, Stacktrace: java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
E/flutter ( 5501):  at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin.lambda$optionsFromResource$4$io-flutter-plugins-firebase-core-FlutterFirebaseCorePlugin(FlutterFirebaseCorePlugin.java:207)
E/flutter ( 5501):  at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
E/flutter ( 5501):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/flutter ( 5501):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/flutter ( 5501):  at java.lang.Thread.run(Thread.java:923)
E/flutter ( 5501): , null)
E/flutter ( 5501): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:242:7)
E/flutter ( 5501): <asynchronous suspension>
E/flutter ( 5501): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter ( 5501): <asynchronous suspension>
E/flutter ( 5501): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter ( 5501): <asynchronous suspension>
E/flutter ( 5501): 
D/ProfileInstaller( 5501): Installing profile for com.example.multi_score
E/flutter ( 5501): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
E/flutter ( 5501): #0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:193:5)
E/flutter ( 5501): #1      Firebase.app (package:firebase_core/src/firebase.dart:56:41)
E/flutter ( 5501): #2      FirebaseAuth.instance (package:firebase_auth/src/firebase_auth.dart:38:47)
E/flutter ( 5501): #3      _WelcomeScreenState.build.<anonymous closure> (package:multi_score/main_screens/welcome_screen.dart:223:46)
E/flutter ( 5501): #4      _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1183:21)
E/flutter ( 5501): #5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:315:24)
E/flutter ( 5501): #6      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:652:11)
E/flutter ( 5501): #7      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:309:5)
E/flutter ( 5501): #8      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:242:7)
E/flutter ( 5501): #9      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:670:9)
E/flutter ( 5501): #10     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
E/flutter ( 5501): #11     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:143:9)
E/flutter ( 5501): #12     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
E/flutter ( 5501): #13     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
E/flutter ( 5501): #14     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
E/flutter ( 5501): #15     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:495:19)
E/flutter ( 5501): #16     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:475:22)
E/flutter ( 5501): #17     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:430:11)
E/flutter ( 5501): #18     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:420:7)
E/flutter ( 5501): #19     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:383:5)
E/flutter ( 5501): #20     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:330:7)
E/flutter ( 5501): #21     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:299:9)
E/flutter ( 5501): #22     _invoke1 (dart:ui/hooks.dart:328:13)
E/flutter ( 5501): #23     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:429:7)
E/flutter ( 5501): #24     _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31)
E/flutter ( 5501): 

pubspec.yaml

name: multi_score
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1

environment:
  sdk: '>=3.3.2 <4.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.6
  animated_text_kit: ^4.2.2
  image_picker: ^1.1.0
  firebase_auth: ^4.19.3
  cloud_firestore: ^4.17.1
  firebase_storage: ^11.7.3
  firebase_core: ^2.30.1

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^3.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - images/
    - images/men/
    - images/try/
    - images/inapp/
    - images/women/
    - images/shoes/
    - images/electronics/
    - images/beauty/
    - images/kids/
    - images/homegarden/
    - images/accessories/
    - images/bags/


  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
  fonts:
    - family: Acme
      fonts:
        - asset: fonts/Acme_Regular.ttf
android flutter firebase dart android-emulator
1个回答
0
投票

错误信息的主要部分是:

无法从资源加载 FirebaseOptions。检查您是否正确定义了values.xml。

看来Firebase客户端找不到它的配置信息。您是否遵循了此处文档中概述的设置过程?这应该会生成一个

firebase_options.dart
文件,Flutter SDK 可以使用该文件来读取配置值。

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