如何在扑翼和火场中使用不同类型的用户进行登录? [英] How to sign in with different types of user in flutter and firebase?
本文介绍了如何在扑翼和火场中使用不同类型的用户进行登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用不同类型的用户登录,我使用Firebase验证器进行登录,并创建了一个以Users和userType作为字段的数据库,那么有谁知道一个函数可以为不同类型的用户显示不同的界面? 我的代码:
class _LoginScreenState extends State<LoginScreen> {
var email;
var password;
var username;
var gender;
var userType;
final usernameController = TextEditingController();
final emailController = TextEditingController();
final passwordController = TextEditingController();
final firestoreInstance = Firestore.instance;
void login() async {
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
firebaseAuth
.signInWithEmailAndPassword(
email: emailController.text, password: passwordController.text)
.then((result) {
{
Navigator.pushReplacementNamed(context, '/homepage');
}
}).catchError((err) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Error"),
content: Text(err.message),
actions: [
FlatButton(
child: Text("Ok"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
});
}
void getUserData() async {
try {
firestoreInstance
.collection('Users')
.document(usernameController.text)
.get()
.then((value) {
setState(() {
email = (value.data)['email'];
password = (value.data)['password'];
gender = (value.data)['gender'];
username = (value.data)['username'];
userType = (value.data)['userType'];
});
});
} catch (e) {
print(e.toString);
}
}
推荐答案
如果您要在登录后导航到其他页面,则类似于:
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
firebaseAuth
.signInWithEmailAndPassword(
email: emailController.text, password: passwordController.text)
.then((result) {
firestoreInstance
.collection('Users')
.document(usernameController.text)
.get()
.then((value) {
var userType = (value.data)['userType'];
if (userType == "firstType") {
Navigator.pushReplacementNamed(context, '/homepage');
}
else if (userType == "secondType") {
Navigator.pushReplacementNamed(context, '/anotherpage');
}
});
}
这篇关于如何在扑翼和火场中使用不同类型的用户进行登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文