目次
alert
Future<void> alert(message) async {
return showDialog<void>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('このページの内容'),
content: Text(message.toString()),
actions: <Widget>[
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
使い方
alert(1223);
alert('test');
confirm
Future<bool?> confirm(message) async {
return showDialog<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('このページの内容'),
content: Text(message.toString()),
actions: <Widget>[
ElevatedButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('OK'),
),
OutlinedButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('キャンセル'),
),
],
),
);
}
使い方
confirm(1223);
if (await confirm('test')) {
// OKを押した!
}
Flutter開発で知らないと損すること