AlertDialog 未在屏幕上显示任何警报
AlertDialog is not showing any alert on the Screen
一旦我按下圆形按钮,如果有任何错误,我希望 flutter 在我的屏幕上通过警告 window 向我显示错误,但它没有这样做。
RoundedButton(
title: 'Register',
onPressed: () async {
setState(() {
showSpinner = true;
});
try {
final newUser = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
Navigator.pushNamed(context, LoginScreen.id);
setState(() {
showSpinner = false;
});
} catch (e) {
build(context);
setState(() {
showSpinner = false;
});
AlertWindow(
error: e.toString(), // Here is the Alert window class
);
}
},
color: Colors.blueAccent,
),
class AlertWindow extends StatelessWidget {
const AlertWindow({Key? key, required this.error}) : super(key: key);
final String error;
@override
Widget build(BuildContext context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 6, sigmaY: 6),
child: AlertDialog(
title: const Text('Alert'),
content: Text(error),
),
);
}
}
如果任何错误来自 firebase,微调器将停止旋转并且不会再发生任何事情。警报 window 没有弹出。
你应该调用 showDialog 函数。
样本:
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return AlertWindow(error: e.toString());
},
);
}
一旦我按下圆形按钮,如果有任何错误,我希望 flutter 在我的屏幕上通过警告 window 向我显示错误,但它没有这样做。
RoundedButton(
title: 'Register',
onPressed: () async {
setState(() {
showSpinner = true;
});
try {
final newUser = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
Navigator.pushNamed(context, LoginScreen.id);
setState(() {
showSpinner = false;
});
} catch (e) {
build(context);
setState(() {
showSpinner = false;
});
AlertWindow(
error: e.toString(), // Here is the Alert window class
);
}
},
color: Colors.blueAccent,
),
class AlertWindow extends StatelessWidget {
const AlertWindow({Key? key, required this.error}) : super(key: key);
final String error;
@override
Widget build(BuildContext context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 6, sigmaY: 6),
child: AlertDialog(
title: const Text('Alert'),
content: Text(error),
),
);
}
}
如果任何错误来自 firebase,微调器将停止旋转并且不会再发生任何事情。警报 window 没有弹出。
你应该调用 showDialog 函数。
样本:
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return AlertWindow(error: e.toString());
},
);
}