Last active
February 18, 2018 07:41
-
-
Save TomoyaShibata/889ca2670abf77d2352cb3eb99a00ca6 to your computer and use it in GitHub Desktop.
Flutter で iOS / Android 向けに合わせた AlertDialog を愚直に出し分けるだけのメモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 使い方 | |
// 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