Future _alertDialog(BuildContext context, {String isi, AlertType alert}) {
return Alert(
context: context,
type: alert,
title: "Notification",
desc: "Laporan telah masuk, silahkan menunggu email dari admin!",
buttons: [
DialogButton(
child: Text(
"OKAY",
style: TextStyle(color: Colors.white, fontSize: 20),
),
onPressed: () => Navigator.pop(
context,
),
width: 120,
)
],
).show();
}
您好,我还是 Flutter 新手,我想尝试在另一个类中创建警报对话框,因此我将其设为可移植类以轻松使用警报。
例如,
我创建了 alertDialog.dart
,我想在 alertDialog.dart
内调用 main.dart
。
但是我出错了
参数类型“Future”不能分配给参数类型“Widget”
对于警报,我使用了另一个依赖
rflutter_alert: ^2.0.2
我正在尝试这个是因为我不了解上下文,我总是得到
<块引用>查找已停用小部件的祖先是不安全的
有什么解决办法吗? 先谢谢你!
答案 0 :(得分:0)
函数 _alertDialog
返回一个 Future
,那么您期望什么?您不能在小部件树中使用 _alertDialog
,因为它不是小部件而是一个函数。相反,将 _alertDialog
称为按钮或类似内容的 onPressed
属性。
我假设 Alert(/*...*/).show();
会返回一个 future,因为它正在等待用户响应,例如单击按钮。当 () => Navigator.pop(context)
在您的 onPressed
的 DialogButton
方法中被调用时,未来可能会完成。
答案 1 :(得分:0)
显示提示功能可以作废
void _showAlert(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Wifi"),
content: Text("Wifi not detected. Please activate it."),
)
);
}