どうも、ちょげ(@chogetarou)です。
CupertinoAlertDialogにボタンを配置する方法を紹介します。
方法

CupertinoAlertDialogにボタンを配置するには、引数「actions」を使います。
具体的には、CupertinoAlertDialogの引数「actions」にリストを指定し、リスト内に配置したいボタンを指定します。
CupertinoAlertDialog(
actions: [
FirstButton(),
SecondButton(),
・・・
],
);
引数「actions」を使うことで、CupertinoAlertDialogにボタンを配置することが出来ます。
使用例
以下は、使用例です。

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: Center(
child: CupertinoButton(
child: Text('Show'),
onPressed: () {
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text("Alert Dialog"),
content: Text('This is Dialog.'),
actions: [
TextButton(
onPressed: () {
print('NO');
Navigator.pop(context);
},
child: Text(
"No",
style: TextStyle(color: Colors.red),
),
),
TextButton(
onPressed: () {
print('OK');
Navigator.pop(context);
},
child: Text('OK'),
),
],
);
},
);
},
),
),
);
}
}

[Flutter]CupertinoAlertDialogの使い方
CupertinoAlertDialogの使い方を解説します。

[Flutter]Cupertino(iOS風)でAlertDialogを表示するには?
CupertinoでAlertDialogを表示する方法を紹介します。

[Flutter]CupertinoDatePickerの分の間隔を設定するには?
CupertinoDatePickerの分単位の間隔を設定する方法を紹介します。

[Flutter]CupertinoAlertDialogの背景色を黒くするには?
CupertinoAlertDialogの背景色を黒くする方法を紹介します。
コメント