gpt4 book ai didi

flutter - Flutter:无法显示AlertDialog

转载 作者:行者123 更新时间:2023-12-03 04:35:44 24 4
gpt4 key购买 nike

当我单击按钮时,我想在完成该过程后显示一个对话框,但是尽管添加了对话框部分,但在屏幕上看不到Alertdialog。
我在哪里做错了?这是我的代码;

   child: InkWell(
onTap: () async {
final selectedLanguage =
await SharedPreferences.getInstance();
final setLanguage =
selectedLanguage.getString('selectedLanguage');
String language =
allTranslations.getLocaleKey(setLanguage);
_forgotPassword =
await createPasswordCode(_controller.text, language);
_dialog('Try');
},
child: Center(
child: Text(
'Send',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
这是我的对话部分
  Widget _dialog(String title) {
return AlertDialog(
title: Text(
title,
style: TextStyle(fontWeight: FontWeight.bold),
),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
actions: [
FlatButton(
child: Text('Approve'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
}

最佳答案

您需要在alertDialog中调用showDialog

InkWell(
onTap: () async {
final selectedLanguage =
await SharedPreferences.getInstance();
final setLanguage =
selectedLanguage.getString('selectedLanguage');
String language =
allTranslations.getLocaleKey(setLanguage);
_forgotPassword =
await createPasswordCode(_controller.text, language);
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return _dialog("try");
},
);
},
child: Center(
child: Text(
'Send',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
))

关于flutter - Flutter:无法显示AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64160818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com