- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试建立一个AlertDialog,以在删除帐户之前重新验证用户。重新验证不起作用时,我想显示错误文本。
通过使用print()语句,可以正确处理错误。但是,我无法获取TextField将错误显示为对用户的反馈。我认为这一定与SimpleDialog本身的状态有关,而不是与外部小部件的状态有关。
这是代码:
Future _validate({String email, String password}) async {
setState(() {
_wrongEmail = false;
_wrongPassword = false;
_emailErrorText = null;
_passwordErrorText = null;
});
try {
if (await userDataBase.checkCorrectEmail(
email: email, loggedInUser: widget.user.id)) {
throw FirebaseAuthException(
message: 'email is not correct', code: 'user-not-found');
}
await userDataBase.authenticateUser(email, password);
} catch (e) {
if (e.code == 'wrong-passwod') {
setState(() {
_passwordErrorText = 'Password not Correct';
});
} else if (e.code == 'user-not-found') {
setState(() {
_emailErrorText = 'Email not Correct';
});
} else {
setState(() {
_emailErrorText = 'Email not Correct';
_passwordErrorText = 'Password not Correct';
_wrongPassword = true;
_wrongEmail = true;
});
}
throw e;
}
}
Future _authenticate({String email, String password}) async {
try {
await _validate(email: email, password: password);
} catch (e) {
print(e.code);
print(_wrongEmail);
print(_emailErrorText);
return;
}
print('correct behaviour');
// Navigator.pop(context);
// setState(() {
// _loading = true;
// });
// await userDataBase.deleteUser(widget.user.id);
// Navigator.of(context).popUntil((route) => route.isFirst);
}
Future _confirmIdentity() {
final emailController = TextEditingController();
final passwordController = TextEditingController();
_emailErrorText = null;
_passwordErrorText = null;
return showDialog(
context: context,
builder: (context) => AlertDialog(
content: Container(
height: 200,
child: Column(
children: [
Text('Confirm Your Identity'),
TextField(
controller: emailController,
decoration: InputDecoration(
errorText: _wrongEmail ? _emailErrorText : null,
labelText: 'email'),
),
TextField(
controller: passwordController,
decoration:
InputDecoration(
errorText: _wrongPassword ? _passwordErrorText : null,
labelText: 'password'
),
),
Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FlatButton(
onPressed: () {
_authenticate(
email: emailController.text,
password: passwordController.text);
},
child: Text('Confirm'),
),
FlatButton(
onPressed: () => Navigator.pop(context),
child: Text('Cancel'),
),
],
)
],
),
),
),
);
}
谢谢。我可以发布所有的小部件代码ecc。如果您需要它:它是一个有状态的小部件。
最佳答案
对于1st 2 if条件,您正在设置错误消息,但未将各自的 bool(boolean) 标志设置为true。
例:
if (e.code == 'wrong-passwod') {
setState(() {
_passwordErrorText = 'Password not Correct';
});
}
在这里,在
setState()
函数中,您还需要设置
_wrongPassword = true;
关于flutter - 在ShowDialog的TextField上显示错误文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65089618/
我不确定这是否被允许,但我有一个主窗体调用另一个带有 ShowDialog 的窗体,它试图调用另一个相同的窗体。 所以,例如: form1 -> form2.showdialog -> form3.s
我听说如果我在没有指定所有者的情况下调用 form.ShowDialog(),那么我可能会在屏幕上看不到对话框表单(它将与其他窗口一起隐藏)。是真的吗?我在没有指定所有者的情况下使用了 ShowDia
ShowDialog(); 和 ShowDialog(IWin32Window); 似乎对我做了完全相同的事情。文档也不是很清楚。 有人告诉我,ShowDialog(IWin32Window); 将确
在我执行函数showDialog 后键盘关闭。但是,我希望键盘保持打开状态并且对话框位于键盘上方。 下面是我的代码。 附言:在this post它表明至少应该以某种方式与 Flutter 一起工作。
我在覆盖、重载等方面很弱,所以我无法处理这个。我的问题是这样的 我有一个 frmDialog。它仅用于显示流程消息、错误消息等。它从日志中获取其文本,因此我不需要将变量传递给它。在每个进程(在其他表单
有时,当我在 WPF 中的 OpenFileDialog 窗口上调用 ShowDialog 时,对话框会立即关闭,返回值为 false。 我正在调用 ShowDialog 以响应按钮单击事件。我可以使
这个问题在这里已经有了答案: How to close Dialog using FlutterDriver (2 个答案) 关闭 2 年前。 我正在使用 FlutterDriver,我定义了一个
我正在使用 ShowDialog()与 WindowStyle = WindowStyle.SingleBorderWindow;在我的 WPF (MVVM) 应用程序中打开一个模式窗口,但它允许我使
WPF的 Window.ShowDialog 方法返回可为空的 bool(boolean) 值。 CommonDialog.ShowDialog 也是如此。 现在,我了解了以下情况:它们将返回fals
有没有办法让窗体闪烁,就像失去焦点时的 ShowDialog? 当您在 Windows 窗体上调用 ShowDialog 并尝试另一个操作时,窗体会闪烁几秒钟然后聚焦。 有没有办法以自定义方式调用闪烁
我的应用程序中有一个表单,通过单击帮助按钮,它会使用函数 show() 打开一个帮助表单。当我使用 showDialog() 从同一个主窗体打开另一个对话框时,帮助窗体被禁用。你有什么主意吗 ?我不想
我有一个强命名程序集。 之前有人问过这个问题......但只是出于不同的目的。 我有一个 Form 基类。当实现类在基类 IsBusy 上设置属性时。我想阻止与表单的所有交互(设置 Enabled =
我只是按照 android 网站的建议定义了一个对话框,但它不会在单击按钮时显示,有些代码是草率的(我没有收到任何错误): static final int DIALOG_A = 1; static
在我公司的企业解决方案中,我正在检查并尽可能多地清除内存泄漏。 我们有一个 BaseCaptureForm,它被许多其他表单(例如 RecommendationCaptureForm)继承。在整个系统
我在我的应用程序中使用了一个自定义的 Messagebox,它继承自 Form 类。当我在我的主窗体上使用它时它工作正常。但是,当我在从主窗体弹出的窗体上使用它的 Show() 函数时,Message
我正在尝试为我们的应用程序实现类似 alt-tab 的行为。当用户按下 ctrl-tab 时,会弹出一个表单(使用 ShowDialog);当他们再次按下它时,它会聚焦应用程序主窗体中的下一个控件。当
我有一个处理订阅数据的 winforms 应用程序。主窗体检查用户是否在数据存储区(xml 文件)中,如果不在,我就调用它。 UserDetails 是一个数据输入表单。 else { For
我有一个表格。 在这种形式中,我在新线程上创建了一个类的实例,因为它运行一些长时间运行的逻辑。该表单还使用户能够取消此逻辑/线程。 如果需要输入,该类会打开一个新表单。 新表格有时会出现在另一个表格后
我有一个 Windows 窗体,如果在加载窗体时满足某些条件,它会弹出一个对话框。问题是窗口没有停留在最上面,我仍然可以点击父级上的东西。但是,表单上有一个按钮,按下时会打开同一个窗口,当我这样做时,
我有两种形式。 LoadWorkstationFile 提示用户输入他们想要加载的 ID。 DisplayDataForm 显示他们在上一个屏幕上选择的 id 的数据。 在 DisplayDataFo
我是一名优秀的程序员,十分优秀!