Flutter 颤振解除警报对话框导航问题
我当前正试图从打开的警报对话框导航回现有屏幕。当我尝试使用此代码执行此操作时: 我被转移回打开的警报对话框,但我希望它在返回原始屏幕时关闭而不是打开。除了使用 这就是我现在要回到的地方:一个打开的对话框 以下是警报对话框代码:Flutter 颤振解除警报对话框导航问题,flutter,flutter-layout,flutter-dependencies,Flutter,Flutter Layout,Flutter Dependencies,我当前正试图从打开的警报对话框导航回现有屏幕。当我尝试使用此代码执行此操作时: 我被转移回打开的警报对话框,但我希望它在返回原始屏幕时关闭而不是打开。除了使用 这就是我现在要回到的地方:一个打开的对话框 以下是警报对话框代码: 您可以尝试如下方式调用警报对话框: class FancyAlertDialog { static showFancyAlertDialog( BuildContext context, String title, String messag
您可以尝试如下方式调用警报对话框:
class FancyAlertDialog {
static showFancyAlertDialog(
BuildContext context,
String title,
String message, {
bool dismissable = false,
Icon icon,
String labelPositiveButton,
String labelNegativeButton,
VoidCallback onTapPositiveButton,
VoidCallback onTapNegativeButton,
}) {
return showDialog(
context: context,
barrierDismissible: dismissable,
child: Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(12.0),
),
),
child: Wrap(
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.0),
topRight: Radius.circular(12.0),
),
color: Colors.white,
),
padding: EdgeInsets.symmetric(vertical: 5.0),
child: Stack(
children: <Widget>[
Align(
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: icon ?? Container(height: 0),
),
alignment: Alignment.topRight,
)
],
),
),
Padding(
padding: EdgeInsets.only(
left: 16.0,
top: 2.0,
right: 16.0,
bottom: 8.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Center(
child: Text(title,
style: khomeStyle.copyWith(
color: Colors.black, fontSize: 16)),
),
SizedBox(height: 8.0),
Text(message,
textAlign: TextAlign.center,
style: khomeStyle.copyWith(
color: Colors.black,
fontSize: 13,
fontWeight: FontWeight.w300)),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(16.0),
),
),
color: Colors.grey,
child: Text(
labelNegativeButton.toUpperCase(),
style: TextStyle(
color: Colors.white,
),
),
onPressed: onTapNegativeButton,
),
),
SizedBox(width: 16.0),
Center(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(16.0),
),
),
color: kOrange,
child: Text(
labelPositiveButton.toUpperCase(),
style: TextStyle(
color: Colors.white,
),
),
onPressed: onTapPositiveButton,
),
),
],
)
],
),
),
],
),
),
);
}
}
调用此函数时,可以在调用警报对话框时调用Navigator.pop(context)
函数作为参数
FancyAlertDialog.showshowFancyAlertDialog(
...
onTapPositiveButton: () {
Navigator.pop(context);
print('tap positive button');
},
)
两个按钮的文本和功能可在调用时指定 请发布完整代码,以便提供适当的帮助和指导。您想导航到警报对话框后面的屏幕还是另一个屏幕?@SimranAswani是的,导航到警报对话框后面的屏幕。您调用警报对话框的地方必须有自己的“上下文”
AlertDialog(
contentPadding: EdgeInsets.all(5.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
),
content: Stack(
overflow: Overflow.visible,
children: <Widget>[
Positioned(
right: -40.0,
top: -40.0,
child: InkResponse(
onTap: () {
Navigator.of(context).pop();
},
child: CircleAvatar(
child: Icon(
Icons.close,
color: Colors.white,
),
backgroundColor: Colors.red,
maxRadius: 20.0,
),
),
),
Navigator.of(context) .push(MaterialPageRoute( builder: (context) => CampaignPage1())) .then((result) { Navigator.of(context).pop();
class FancyAlertDialog {
static showFancyAlertDialog(
BuildContext context,
String title,
String message, {
bool dismissable = false,
Icon icon,
String labelPositiveButton,
String labelNegativeButton,
VoidCallback onTapPositiveButton,
VoidCallback onTapNegativeButton,
}) {
return showDialog(
context: context,
barrierDismissible: dismissable,
child: Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(12.0),
),
),
child: Wrap(
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.0),
topRight: Radius.circular(12.0),
),
color: Colors.white,
),
padding: EdgeInsets.symmetric(vertical: 5.0),
child: Stack(
children: <Widget>[
Align(
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: icon ?? Container(height: 0),
),
alignment: Alignment.topRight,
)
],
),
),
Padding(
padding: EdgeInsets.only(
left: 16.0,
top: 2.0,
right: 16.0,
bottom: 8.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Center(
child: Text(title,
style: khomeStyle.copyWith(
color: Colors.black, fontSize: 16)),
),
SizedBox(height: 8.0),
Text(message,
textAlign: TextAlign.center,
style: khomeStyle.copyWith(
color: Colors.black,
fontSize: 13,
fontWeight: FontWeight.w300)),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(16.0),
),
),
color: Colors.grey,
child: Text(
labelNegativeButton.toUpperCase(),
style: TextStyle(
color: Colors.white,
),
),
onPressed: onTapNegativeButton,
),
),
SizedBox(width: 16.0),
Center(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(16.0),
),
),
color: kOrange,
child: Text(
labelPositiveButton.toUpperCase(),
style: TextStyle(
color: Colors.white,
),
),
onPressed: onTapPositiveButton,
),
),
],
)
],
),
),
],
),
),
);
}
}
FancyAlertDialog.showshowFancyAlertDialog(*Supply your arguments here*)
FancyAlertDialog.showshowFancyAlertDialog(
...
onTapPositiveButton: () {
Navigator.pop(context);
print('tap positive button');
},
)