Skip to content

Instantly share code, notes, and snippets.

@TomoyaShibata
Last active February 18, 2018 07:41
Show Gist options
  • Save TomoyaShibata/889ca2670abf77d2352cb3eb99a00ca6 to your computer and use it in GitHub Desktop.
Save TomoyaShibata/889ca2670abf77d2352cb3eb99a00ca6 to your computer and use it in GitHub Desktop.
Flutter で iOS / Android 向けに合わせた AlertDialog を愚直に出し分けるだけのメモ
// 使い方
// showDialog(context: context, child: this._getAlertDialog());
Widget _getAlertDialog() {
var title = new Text("AlertDialog");
var listBody = new ListBody(
children: [
new Text("AlertDialog body text."),
],
);
var androidAction = new FlatButton(
child: new Text('Regret'),
onPressed: () => Navigator.of(context).pop(),
);
var iOSAction = new CupertinoButton(
child: new Text('Regret'),
onPressed: () => Navigator.of(context).pop(),
);
return Theme.of(context).platform == TargetPlatform.iOS
? new CupertinoAlertDialog(
title: title,
content: new SingleChildScrollView(
child: listBody,
),
actions: <Widget>[iOSAction],
)
: new AlertDialog(
title: title,
content: new SingleChildScrollView(
child: listBody,
),
actions: <Widget>[androidAction],
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment