我在屏幕上有两个_displayDialog()
方法。两者似乎都使用相同的上下文。当我单击一个警报框中的按钮时,应在其中弹出警报框,它会取消应用程序并导航到主屏幕。
_onBackPressed()
和_onBackPressed()
包含两个警报框。
_displayDialog()
取消了该应用程序,并且 //* This is the code for cancelling the applcation
Future<bool> _onBackPressed() {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Do you really want to exit the app?"),
actions: <Widget>[
FlatButton(
child: Text("No"),
onPressed: () => Navigator.pop(context, false),
),
FlatButton(
child: Text("Yes"),
onPressed: () => Navigator.pop(context, true),
),
],
),
);
}
//* Dialog box requesting the contact info of user
_displayDialog(BuildContext context) async {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Enter a phone number to contact you for the delivery.'),
content: TextField(
autofocus: false,
controller: _textFieldController,
keyboardType: TextInputType.phone,
maxLength: 10,
decoration: InputDecoration(
hintText: "Enter a contact number",
prefixIcon: Icon(Icons.phone),
errorText: _validate ? 'Value Can\'t Be Empty' : null,
),
),
actions: <Widget>[
new FlatButton(
child: new Text('Done'),
onPressed: () {
numberValidation();
},
)
],
);
},
);
}
numberValidation() {
if (_textFieldController.text.isEmpty) {
print("Number not entered");
} else {
setState(() {
contact = _textFieldController.text;
createOrder();
Navigator.of(context).pop();
});
}
}
//* Function that creates CRM leads
createOrder() async {
Navigator.of(context).pop();
_getOrders().then((_) {
return Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (BuildContext context) => new LocationRoute(),
));
});
}
打开了一个框,当我们单击“完成”时,它会弹出警报框并导航到新页面。
问题是“完成”按钮会弹出框并移至主屏幕,而不是所需的屏幕
{{1}}