「Flutter/alert」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→OK/Cancel確認フォーム) |
(→iOSスタイルの複数選択) |
||
| (同じ利用者による、間の5版が非表示) | |||
| 行1: | 行1: | ||
| + | ==一択確認アラート== | ||
| + | <pre> | ||
| + | showDialog( | ||
| + | context: context, | ||
| + | builder: (context) { | ||
| + | return AlertDialog( | ||
| + | title: Text( | ||
| + | 'タイトル', style: TextStyle(locale: Locale("ja", "JP"))), | ||
| + | content: SingleChildScrollView( | ||
| + | child: ListBody( | ||
| + | children: <Widget>[ | ||
| + | Text('本文。', | ||
| + | style: TextStyle(locale: Locale("ja", "JP"))), | ||
| + | ], | ||
| + | ), | ||
| + | ), | ||
| + | actions: <Widget>[ | ||
| + | FlatButton( | ||
| + | child: Text('ok'), | ||
| + | onPressed: () { | ||
| + | Navigator.of(context).pop(); | ||
| + | }, | ||
| + | ), | ||
| + | ], | ||
| + | ); | ||
| + | }, | ||
| + | ); | ||
| + | </pre> | ||
| + | |||
==OK/Cancel確認フォーム== | ==OK/Cancel確認フォーム== | ||
<pre> | <pre> | ||
| 行24: | 行53: | ||
参考:https://qiita.com/coka__01/items/4c1aea5fb1646e463f91 | 参考:https://qiita.com/coka__01/items/4c1aea5fb1646e463f91 | ||
| + | |||
| + | ==複数選択== | ||
| + | <pre> | ||
| + | showDialog( | ||
| + | context: context, | ||
| + | builder: (context) { | ||
| + | return SimpleDialog( | ||
| + | title: Text("タイトル"), | ||
| + | children: <Widget>[ | ||
| + | SimpleDialogOption( | ||
| + | child: Text("編集", style: TextStyle(locale: Locale("ja", "JP"))), | ||
| + | onPressed: () => Navigator.pop(context), | ||
| + | ), | ||
| + | SimpleDialogOption( | ||
| + | child: Text("操作", style: TextStyle(locale: Locale("ja", "JP"))), | ||
| + | onPressed: () => Navigator.pop(context), | ||
| + | ), | ||
| + | SimpleDialogOption( | ||
| + | child: Text("削除", style: TextStyle(locale: Locale("ja", "JP"))), | ||
| + | onPressed: () => Navigator.pop(context), | ||
| + | ), | ||
| + | ], | ||
| + | ); | ||
| + | }, | ||
| + | ); | ||
| + | </pre> | ||
| + | |||
| + | ==iOSスタイルの複数選択== | ||
| + | <pre> | ||
| + | showCupertinoModalPopup( | ||
| + | context: context, | ||
| + | builder: (BuildContext context) { | ||
| + | return CupertinoActionSheet( | ||
| + | title: const Text('タイトル'), | ||
| + | actions: <Widget>[ | ||
| + | CupertinoActionSheetAction( | ||
| + | child: const Text('選択1'), | ||
| + | onPressed: () { | ||
| + | Navigator.pop(context, '選択1'); | ||
| + | }, | ||
| + | ), | ||
| + | CupertinoActionSheetAction( | ||
| + | child: const Text('選択2'), | ||
| + | onPressed: () { | ||
| + | Navigator.pop(context, '選択2'); | ||
| + | }, | ||
| + | ), | ||
| + | CupertinoActionSheetAction( | ||
| + | child: const Text('選択3'), | ||
| + | onPressed: () { | ||
| + | Navigator.pop(context, '選択3'); | ||
| + | }, | ||
| + | ), | ||
| + | ], | ||
| + | cancelButton: CupertinoActionSheetAction( | ||
| + | child: const Text('キャンセル選択'), | ||
| + | isDefaultAction: true, | ||
| + | onPressed: () { | ||
| + | Navigator.pop(context, 'キャンセル選択'); | ||
| + | }, | ||
| + | )); | ||
| + | }); | ||
| + | </pre> | ||
| + | |||
| + | 参考:https://qiita.com/nagahama/items/fe3b6ba210f9bfdb6408 | ||
2019年12月6日 (金) 18:52時点における最新版
一択確認アラート
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'タイトル', style: TextStyle(locale: Locale("ja", "JP"))),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('本文。',
style: TextStyle(locale: Locale("ja", "JP"))),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('ok'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
OK/Cancel確認フォーム
showDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text("タイトル1"),
content: Text("本文1"),
actions: <Widget>[
CupertinoDialogAction(
child: Text("Cancel"),
isDestructiveAction: true,
onPressed: () => Navigator.pop(context),
),
CupertinoDialogAction(
child: Text("OK"),
onPressed: () => Navigator.pop(context),
),
],
);
},
);
参考:https://qiita.com/coka__01/items/4c1aea5fb1646e463f91
複数選択
showDialog(
context: context,
builder: (context) {
return SimpleDialog(
title: Text("タイトル"),
children: <Widget>[
SimpleDialogOption(
child: Text("編集", style: TextStyle(locale: Locale("ja", "JP"))),
onPressed: () => Navigator.pop(context),
),
SimpleDialogOption(
child: Text("操作", style: TextStyle(locale: Locale("ja", "JP"))),
onPressed: () => Navigator.pop(context),
),
SimpleDialogOption(
child: Text("削除", style: TextStyle(locale: Locale("ja", "JP"))),
onPressed: () => Navigator.pop(context),
),
],
);
},
);
iOSスタイルの複数選択
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) {
return CupertinoActionSheet(
title: const Text('タイトル'),
actions: <Widget>[
CupertinoActionSheetAction(
child: const Text('選択1'),
onPressed: () {
Navigator.pop(context, '選択1');
},
),
CupertinoActionSheetAction(
child: const Text('選択2'),
onPressed: () {
Navigator.pop(context, '選択2');
},
),
CupertinoActionSheetAction(
child: const Text('選択3'),
onPressed: () {
Navigator.pop(context, '選択3');
},
),
],
cancelButton: CupertinoActionSheetAction(
child: const Text('キャンセル選択'),
isDefaultAction: true,
onPressed: () {
Navigator.pop(context, 'キャンセル選択');
},
));
});
