Flutter & AlertDialog:我的应用程序在加载后不显示警报对话框
Flutter & AlertDialog : My app doesn't show the alert dialog after loading
Flutter 和 AlertDialog:我的应用程序在加载后不显示警报对话框。
即使在打印警告对话框之前和之后的 2 次打印,也跳过了对话框。这是为什么?请帮我解决这个问题。
onTap: () async {
if (_formKey.currentState.validate() &&
_ratingStar > 0) {
setState(() {
_loading = true;
});
dynamic result =
await User_DatabaseService().uploadFeedback(
comment: review );
setState(() {
_loading = false;
});
if (result) {
print('Before dialog');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6.0))),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(
vertical: 60, horizontal: 10),
child: Text(
//'Please rate with star',
'평가해 주셔서 감사합니다!',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
height: 50,
//color: primaryColor,
child: Text(
AppLocalizations.of(context)
.translate('OKAY'),
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold),
),
),
),
],
),
);
},
);
print('After dialog');
Navigator.pop(context);
} else {
print('Sth wrong');
}
} else {
print('Not submit');
}
},
请查看我的代码并告诉我哪里出了问题。谢谢你。期待您的来信。
这是问题所在:
if (result) {
print('Before dialog');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6.0))),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(
vertical: 60, horizontal: 10),
child: Text(
//'Please rate with star',
'평가해 주셔서 감사합니다!',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
height: 50,
//color: primaryColor,
child: Text(
AppLocalizations.of(context)
.translate('OKAY'),
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold),
),
),
),
],
),
);
},
);
print('After dialog');
Navigator.pop(context);
} else {
print('Sth wrong');
}
您正在呈现对话,然后将其弹出。确保添加 Navigator.pop(context) 方法,仅在您单击警报对话框上的按钮后。所以,像这样重写代码:
if (result) {
print('Before dialog');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6.0))),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(
vertical: 60, horizontal: 10),
child: Text(
//'Please rate with star',
'평가해 주셔서 감사합니다!',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
height: 50,
//color: primaryColor,
child: Text(
AppLocalizations.of(context)
.translate('OKAY'),
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold),
),
),
),
],
),
);
},
);
print('After dialog');
} else {
print('Sth wrong');
}
问题出在 print('After dialog')
行之后的行。您正在执行 Navigator.pop(context);
,这基本上是从导航堆栈中删除对话框。
扑朔迷离:
showDialog()
用于显示对话框。并且Navigator.pop(context)
用于删除对话框
Flutter 和 AlertDialog:我的应用程序在加载后不显示警报对话框。 即使在打印警告对话框之前和之后的 2 次打印,也跳过了对话框。这是为什么?请帮我解决这个问题。
onTap: () async {
if (_formKey.currentState.validate() &&
_ratingStar > 0) {
setState(() {
_loading = true;
});
dynamic result =
await User_DatabaseService().uploadFeedback(
comment: review );
setState(() {
_loading = false;
});
if (result) {
print('Before dialog');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6.0))),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(
vertical: 60, horizontal: 10),
child: Text(
//'Please rate with star',
'평가해 주셔서 감사합니다!',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
height: 50,
//color: primaryColor,
child: Text(
AppLocalizations.of(context)
.translate('OKAY'),
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold),
),
),
),
],
),
);
},
);
print('After dialog');
Navigator.pop(context);
} else {
print('Sth wrong');
}
} else {
print('Not submit');
}
},
请查看我的代码并告诉我哪里出了问题。谢谢你。期待您的来信。
这是问题所在:
if (result) {
print('Before dialog');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6.0))),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(
vertical: 60, horizontal: 10),
child: Text(
//'Please rate with star',
'평가해 주셔서 감사합니다!',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
height: 50,
//color: primaryColor,
child: Text(
AppLocalizations.of(context)
.translate('OKAY'),
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold),
),
),
),
],
),
);
},
);
print('After dialog');
Navigator.pop(context);
} else {
print('Sth wrong');
}
您正在呈现对话,然后将其弹出。确保添加 Navigator.pop(context) 方法,仅在您单击警报对话框上的按钮后。所以,像这样重写代码:
if (result) {
print('Before dialog');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6.0))),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(
vertical: 60, horizontal: 10),
child: Text(
//'Please rate with star',
'평가해 주셔서 감사합니다!',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
height: 50,
//color: primaryColor,
child: Text(
AppLocalizations.of(context)
.translate('OKAY'),
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold),
),
),
),
],
),
);
},
);
print('After dialog');
} else {
print('Sth wrong');
}
问题出在 print('After dialog')
行之后的行。您正在执行 Navigator.pop(context);
,这基本上是从导航堆栈中删除对话框。
扑朔迷离:
showDialog()
用于显示对话框。并且Navigator.pop(context)
用于删除对话框