目標:
1.按下刪除按鈕時,會跳出提示框提醒是否要刪除
2.按下product_create頁面的save時,會跳出光箱
_showWarningDialog(BuildContext context) {
showDialog(
context: context,
//一定要傳入基本訊息
builder: (BuildContext context) {
return AlertDialog(
title: Text('Are you sure?'),
content: Text('This action cannot be undone!'),
actions: <Widget>[
FlatButton(
child: Text('DISCARD'),
onPressed: () {
Navigator.pop(context);
//基本訊息在這用上了
//回到上一層而已,不做其他事
},
),
FlatButton(
child: Text('CONTINUE'),
onPressed: () {
Navigator.pop(context);
Navigator.pop(context, true);
//回到上一層
//然後傳一個true到products.dart的Navigator後的then那邊
//因為那邊有寫deleteProduct
//所以就進行刪除
},
),
],
);
});
}
再註冊即可
...
child: RaisedButton(
color: Theme.of(context).accentColor,
child: Text('DELETE'),
onPressed: () => _showWarningDialog(context),
),
...
child: RaisedButton(
child: Text('Save'),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Center(
child: Text('This is a Modal!'),
);
});
},
),
主題來源:
Learn Flutter & Dart to Build iOS & Android Apps