enum ConfirmAction { ACCEPT, CANCEL }
Future<ConfirmAction?> confirmDialog(BuildContext context) async {
/*
Sample:
onPressed: () async {
final ConfirmAction? action = await confirmDialog(context);
print("你選擇:$action");
},
*/
return showDialog<ConfirmAction>(
context: context,
barrierDismissible: false, //控制點擊對話框以外的區域是否隱藏對話框
builder: (BuildContext context) {
return AlertDialog(
title: Text('確認取消對話視窗'),
content: const Text('內容訊息'),
actions: <Widget>[
FlatButton(
child: const Text('確認'),
onPressed: () {
Navigator.of(context).pop(ConfirmAction.ACCEPT);
},
),
FlatButton(
child: const Text('取消'),
onPressed: () {
Navigator.of(context).pop(ConfirmAction.CANCEL);
},
)
],
);
},
);
}
import 'package:flutter/material.dart';
import 'package:untitled/Constants.dart';
class detailpage extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: appBackgroundGreyColor,
body: _detailpage(),
);
}
}
class _detailpage extends StatelessWidget{
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
child: Text("Return"),
onPressed: () async {
final ConfirmAction? action = await confirmDialog(context);
print("你選擇:$action");
Navigator.pop(context);
},
),
);
}
}
沒有留言:
張貼留言