Flutter Web:MissingPluginException(未在频道 plugins.flutter.io/firebase_auth 上找到方法 startListeningAuthState 的实现)

Flutter Web: MissingPluginException(No implementation found for method startListeningAuthState on channel plugins.flutter.io/firebase_auth)

我最近将我的 Flutter Firebase 应用程序转换为 Flutter Web,但在尝试登录或注册后出现此错误:

MissingPluginException(No implementation found for method startListeningAuthState on channel plugins.flutter.io/firebase_auth)

我向我的 Firebase 项目添加了新的网络应用程序,粘贴了代码,但它似乎不起作用。任何解决方案?我想尽可能地保持我的代码相同,但我会感谢每一个答案。谢谢! 我的 index.html:

    <body>

      <!-- The core Firebase JS SDK is always required and must be listed first -->
      <script src="https://www.gstatic.com/firebasejs/7.21.1/firebase-app.js"></script>

      <!-- TODO: Add SDKs for Firebase products that you want to use
           https://firebase.google.com/docs/web/setup#available-libraries -->
      <script src="https://www.gstatic.com/firebasejs/7.21.1/firebase-analytics.js"></script>
      <script src="https://www.gstatic.com/firebasejs/7.21.1/firebase-auth.js"></script>
      <script src="https://www.gstatic.com/firebasejs/7.21.1/firebase-firestore.js"></script>

      <script>
        // Your web app's Firebase configuration
        // For Firebase JS SDK v7.20.0 and later, measurementId is optional
        var firebaseConfig = {
          apiKey: "**",
          authDomain: "***",
          databaseURL: "h****",
          projectId: "%%%",
          storageBucket: "%%%%",
          messagingSenderId: "%%%%",
          appId: "%%%%",
          measurementId: "%%%%"
        };
        // Initialize Firebase
        if(!firebase.apps.length){
          firebase.initializeApp(firebaseConfig);
          firebase.analytics();
          firebase.auth();
          firebase.firestore();
        };
      </script>

      <!-- This script installs service_worker.js to provide PWA functionality to
           application. For more information, see:
           https://developers.google.com/web/fundamentals/primers/service-workers -->
      <script>
        if ('serviceWorker' in navigator) {
          window.addEventListener('load', function () {
            navigator.serviceWorker.register('flutter_service_worker.js');
          });
        }
      </script>
      <script src="main.dart.js" type="application/javascript"></script>
    </body>

我的pubspec.yaml:

dependencies:
      flutter:
        sdk: flutter
      firebase_auth: ^0.14.0+5
      cloud_firestore: ^0.12.9+4
      firebase_core: ^0.4.4+3
      firebase_storage: 3.0.4
      provider: ^3.1.0
      image_cropper: ^1.2.0
      image_picker: ^0.6.5
      outline_gradient_button: ^1.0.0+2
      page_transition: ^1.1.6
      share: ^0.6.4+3
      intl: ^0.16.1
      photo_view: ^0.10.2
      skeleton_text: ^1.0.0
      url_launcher: ^5.4.5
      admob_flutter: ^0.3.4
      file_picker: ^2.0.0
      flutter_downloader: ^1.5.0
      path_provider: ^1.6.18
      permission_handler: ^5.0.1+1
      ext_storage: ^1.0.3
      connectivity: ^0.4.9+3

我的auth.dart:

import 'package:classy/pages/blank.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/services.dart';
import 'user.dart';

class AuthService {
  String exceptionError;

  final FirebaseAuth _auth = FirebaseAuth.instance;

  //Creating user object
  User userFromFirebaseUser(FirebaseUser user){
    return user != null ? User(uid: user.uid) : null;
  }

  void currentUser() async{
    final FirebaseUser user = await _auth.currentUser();
  }

  //auth change user stream
  Stream<User> get user{
    return _auth.onAuthStateChanged.map((FirebaseUser user) => userFromFirebaseUser(user));
  }

  //Registering with email and password
  Future register(String email, String password, context) async {
    try{
      AuthResult result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
      FirebaseUser user = result.user;
      Navigator.popUntil(context, ModalRoute.withName("/"));
//      Navigator.pushReplacementNamed(context, '/wrapper');
      return userFromFirebaseUser(user);

    }
    on PlatformException catch(e){
      if(e.message.startsWith('The email address is already in use')){
        exceptionError='Użytkownik z podanym adresem email już istnieje';
      }
      if(e.message.startsWith('The email address is badly formatted')){
        exceptionError='Wpisz poprawny adres email';
      }
      return null;
    }
  }

  //Logging with email and password
  Future login(String email, String password, context) async {
    try{
      AuthResult result = await _auth.signInWithEmailAndPassword(email: email, password: password);
      FirebaseUser user = result.user;
      Navigator.pop(context);
      return userFromFirebaseUser(user);
    }
    on PlatformException catch(e){
      if(e.message.startsWith('The password is invalid')){
        exceptionError='Wpisz poprawne hasło';
      }
      if(e.message.startsWith('There is no user record')){
        exceptionError='Użytkownik z podanym email nie istnieje';
      }
      return null;
    }
  }
}

将您的 FireAuth 版本更新为 firebase_auth:^0.18.4+1 如果在更新 pubspec 期间出现任何其他错误,请将其他依赖项更新为更新版本。

[在 BR 中回答]

将您的 FireAuth 版本更新为 firebase_auth:^0.18.4+1 如果在 pubspec 更新期间出现其他错误,请将其他依赖项更新为更新版本。

对我有用的是 delete/comment 删除所有与 firebase 相关的依赖项,然后使用 flutter pub add *dependency name*

一个一个地重新安装

这确保我安装了最新的依赖项并且没有冲突