我正在嘗試在提供程式商店中撰寫 showDialog 函式,這樣我就可以分離 UI 代碼和業務邏輯代碼。但是,我無法在 showDialog 中撰寫背景關系并導致未定義名稱“背景關系”的錯誤。我想知道為什么我不能在提供程式中撰寫背景關系以及如何解決這個問題。
這是提供程式代碼,我想放 showDialog 函式。
class LoginSignupData extends ChangeNotifier{
final authentication = FirebaseAuth.instance;
bool isSignup = true;
bool isSignupValid = false;
final formKey = GlobalKey<FormState>();
String userName = '';
String userEmail = '';
String userPassword = '';
String nameError = 'Please enter at least 4 characters';
String emailError = 'Please enter a valid email address.';
String passwordError = 'Password must be at least 7 characters long.';
changeBool(status){
isSignup = status;
notifyListeners();
}
signIn() async{
showDialog(
context: context, // error
barrierDismissible: false,
builder: (context) => const Center(child: CircularProgressIndicator(),)
)
try {
await authentication.signInWithEmailAndPassword(
email: userEmail, password: userPassword
);
} on FirebaseAuthException catch (e) {
print('FirebaseAuthException : $e');
}
notifyListeners();
}
tryValidation() {
final isValid = formKey.currentState!.validate();
if (isValid) {
formKey.currentState!.save();
isSignupValid = true;
notifyListeners();
}
notifyListeners();
}
}`
uj5u.com熱心網友回復:
宣告signIn()函式時,讓它像這樣signIn(BuildContext context)......然后當你從另一個方法/函式呼叫它時,確保傳遞你從中呼叫它的背景關系......像這樣......signIn(context)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/490338.html
上一篇:我打算在Dart中正常定義和使用setter,但出現錯誤:方法'setAnimal'沒有為型別'AnimalCage'定義
