[英]Flutter Firebase Authentication requires 2 clicks for sign in
我剛剛將我的應用程序與 firebase 身份驗證相關聯,但是當我嘗試單擊登錄按鈕時:它說
W/System ( 6835): Ignoring header X-Firebase-Locale because its value was null.
這是我關於 firebase 身份驗證的代碼:`
void signIn() async{
final User? user = (await auth.signInWithEmailAndPassword(email: mailController.text, password: passController.text)).user;
final uid = user!.uid;
if(uid != null){
if(this.mounted){
setState((){
success = 2;
userMail = user.email!;
userName = userMail;
userName = userMail.replaceFirst(userName[0],"");
userName = userName.substring(0,userName.indexOf("@"));
userName = userName.replaceFirst(userName[0],userName[0].toUpperCase());
});
}}
else{
setState((){
success = 3;
});
}
}
`
if(success == 2){
if(userMail.startsWith("1")){
Navigator.pushReplacement(context,MaterialPageRoute(builder:(context) => OgrenciPage(mail:userName)));
}
``
我試圖創建 sha-1 密鑰,關閉藍牙連接,但它從來沒有用過。
我之前也遇到過這個問題,然后通過使函數 Future asyn{} 和使用 try catch 塊來解決這個問題。
在我的例子中,我創建了登錄類模型,我在其中執行所有登錄/注冊功能
這是示例代碼,您可以在其中了解如何管理它:
class Login {
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
Future<void> signInUser(
String email, String password, BuildContext context) async {
try {
await firebaseAuth.signInWithEmailAndPassword(
email: email, password: password);
} on FirebaseAuthException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
e.toString(),
),
backgroundColor: Colors.redAccent,
duration: const Duration(seconds: 2),
),
);
} catch (error) {
rethrow;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.