使用提供商时Firebaseauth的错误
我想用firebase_auth创建一个输入页面。我可以成功登录,但无法登录。当我尝试登录应用程序时,没有给出任何错误,但不会传递主页。仍然在登录页面中。现在,当我重新启动调试时,它会通过主页。你能看到我的代码并帮助我吗?
这是我的身份服务代码
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:library_app/models/person.dart';
class FirebaseAuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
Person? _createPerson(User? user) {
return user == null ? null : Person.fromFirebaseUser(user);
}
Stream<Person?> get statusFollower {
return _auth.authStateChanges().map(_createPerson);
}
void createUserEmailAndPassword({
required String email,
required String password,
}) async {
try {
var _userCredential = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
_createPerson(_userCredential.user);
} catch (e) {
debugPrint(e.toString());
}
}
loginUserEmailAndPassword({
required String email,
required String password,
}) async {
try {
var _userCredential = await _auth.signInWithEmailAndPassword(
email: email,
password: password,
);
_createPerson(_userCredential.user);
} catch (e) {
debugPrint(e.toString());
}
}
void signOut() async {
await _auth.signOut();
}
}
,这是我的方向代码
import 'package:flutter/cupertino.dart';
import 'package:library_app/models/person.dart';
import 'package:library_app/pages/error_page.dart';
import 'package:library_app/pages/loading_page.dart';
import 'package:library_app/pages/main_page.dart';
import 'package:library_app/pages/sign_in_page.dart';
import 'package:library_app/services/firebase_auth_service.dart';
import 'package:provider/provider.dart';
class OrientationSystem extends StatelessWidget {
const OrientationSystem({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var _authService = Provider.of<FirebaseAuthService>(context, listen: false);
return StreamBuilder<Person?>(
stream: _authService.statusFollower,
builder: (context, stream) {
if (stream.connectionState == ConnectionState.waiting) {
return const LoadingPage();
}
if (stream.hasData) {
return const MainPage();
}
if (!stream.hasData) {
return const SigInPage();
} else {
return const ErrorPage();
}
},
);
}
}
我该怎么办? 请帮忙...
I want to create an entering page with firebase_auth. I can sign in successfully but I can't log in. When I try to log in application doesn't give any error but it isn't pass the main page. Still it is in log in page. When I restart the debugging now it pass the main page. Can you see my code and help me?
Here is my auth service code
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:library_app/models/person.dart';
class FirebaseAuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
Person? _createPerson(User? user) {
return user == null ? null : Person.fromFirebaseUser(user);
}
Stream<Person?> get statusFollower {
return _auth.authStateChanges().map(_createPerson);
}
void createUserEmailAndPassword({
required String email,
required String password,
}) async {
try {
var _userCredential = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
_createPerson(_userCredential.user);
} catch (e) {
debugPrint(e.toString());
}
}
loginUserEmailAndPassword({
required String email,
required String password,
}) async {
try {
var _userCredential = await _auth.signInWithEmailAndPassword(
email: email,
password: password,
);
_createPerson(_userCredential.user);
} catch (e) {
debugPrint(e.toString());
}
}
void signOut() async {
await _auth.signOut();
}
}
And here is my orientation code
import 'package:flutter/cupertino.dart';
import 'package:library_app/models/person.dart';
import 'package:library_app/pages/error_page.dart';
import 'package:library_app/pages/loading_page.dart';
import 'package:library_app/pages/main_page.dart';
import 'package:library_app/pages/sign_in_page.dart';
import 'package:library_app/services/firebase_auth_service.dart';
import 'package:provider/provider.dart';
class OrientationSystem extends StatelessWidget {
const OrientationSystem({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var _authService = Provider.of<FirebaseAuthService>(context, listen: false);
return StreamBuilder<Person?>(
stream: _authService.statusFollower,
builder: (context, stream) {
if (stream.connectionState == ConnectionState.waiting) {
return const LoadingPage();
}
if (stream.hasData) {
return const MainPage();
}
if (!stream.hasData) {
return const SigInPage();
} else {
return const ErrorPage();
}
},
);
}
}
what must I do?
please help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有在 firbaseauthservice 结构中延伸或与changeNotifier类一起使用。此外,您需要在执行任务后或更新Firebaseauthservice类中的数据后 notifyListener(),以便您的其他类可以收听更新的值。
但是,请将您的问题更新为“使用提供商时Firebaseauth中的错误”之类的问题。使您的问题标题尽可能多地相关,否则您可能会被系统禁止。这是一个建议。
You did not extend or used with ChangeNotifier class in the FirebaseAuthService construction. Also, you need to notifyListener() after doing the tasks or after updating data inside your FirebaseAuthService class so that your other classes may listen to the updated values.
However, please update your question to something like "Error in FirebaseAuth while using Provider". Make your question titles as much relevant as you can otherwise you might get ban by the system. This is a suggestion.