我最近将Flutter Firebase应用程序转换为Flutter Web,尝试登录或注册后出现此错误:
MissingPluginException(No implementation found for method startListeningAuthState on channel plugins.flutter.io/firebase_auth)
我在Firebase项目中添加了新的Web应用程序,粘贴了代码,但似乎不起作用。有什么办法吗?我想尽可能地保持我的代码不变,但是我会很感激每一个答案。谢谢! 我的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
我的验证标:
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;
}
}
}
答案 0 :(得分:0)
将您的 FireAuth 版本更新为 firebase_auth:^0.18.4+1 如果在 pubspec 更新期间出现任何其他错误,请将其他依赖项更新为更新版本。
[Resposta em BR]
实现 versão do seu FireAuth 对 firebase_auth:^0.18.4+1 se durante a atualização do pubspec algum outro erro foi apresentado atualize as demaisdependentências para versões atualizadas.
答案 1 :(得分:0)
对我有用的是删除/注释掉所有与 firebase 相关的依赖项并使用 flutter pub add *dependency name*
这确保我安装了最新的依赖项并且没有冲突