Flutter 使用作用域模型显示对话框
我有一个基本的登录表单,带有我的Flutter 使用作用域模型显示对话框,flutter,scoped-model,Flutter,Scoped Model,我有一个基本的登录表单,带有我的LoginModel。 但是我不明白如何调用函数notifyListeners在我的视图中显示对话框 登录小部件: @override Widget build(BuildContext context) { return new Scaffold( body: new ScopedModel<LoginModel>( model: _loginModel, child:
LoginModel
。
但是我不明白如何调用函数notifyListeners
在我的视图中显示对话框
登录小部件:
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new ScopedModel<LoginModel>(
model: _loginModel,
child: Center(child: ScopedModelDescendant<LoginModel>(
builder: (context, child, model) {
if (model.status == Status.LOADING) {
return Loading();
}
else return showForm(context);
}))));
}
当
状态
为错误时,我需要显示一个对话框
最后我得到了这个,只是在方法onLogin中返回了一个未来
Future<bool> onLogin(String username, String password) async {
_status = Status.LOADING;
notifyListeners();
try {
await api.login();
_status = Status.SUCCESS;
notifyListeners();
return true;
} catch (response) {
_status = Status.ERROR;
notifyListeners();
return false;
}
}
Future<bool> onLogin(String username, String password) async {
_status = Status.LOADING;
notifyListeners();
try {
await api.login();
_status = Status.SUCCESS;
notifyListeners();
return true;
} catch (response) {
_status = Status.ERROR;
notifyListeners();
return false;
}
}
onPressed: () async {
bool success = await _loginModel.onLogin(_usernameController.text, _passwordController.text);
if(success) {
Navigator.pop(context, true);
}
else{
_showDialogError();
}
}