Created
December 22, 2019 16:49
-
-
Save stefanasandei/13d5db9ebedf5e75c3493070f70325cb to your computer and use it in GitHub Desktop.
This file contains 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
import 'package:flutter/material.dart'; | |
import 'package:flutter/cupertino.dart'; | |
void main() { | |
runApp(new MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return new MaterialApp( | |
home: new UserOptions(), | |
); | |
} | |
} | |
class UserOptions extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() { | |
return new UserOptionsState(); | |
} | |
} | |
class UserOptionsState extends State<UserOptions> { | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text('data'), | |
), | |
body: new Builder( | |
builder: (BuildContext context) { | |
return Center( | |
child: ListView( | |
children: <Widget> [ | |
RaisedButton( | |
child: Text('Open CupertinoActionSheet'), | |
onPressed: () { | |
containerForSheet<String>( | |
context: context, | |
child: CupertinoActionSheet( | |
title: const Text('Choose frankly π'), | |
message: const Text( | |
'Your options are '), | |
actions: <Widget>[ | |
CupertinoActionSheetAction( | |
child: const Text('π Yes'), | |
onPressed: () { | |
Navigator.pop(context, 'π Yes'); | |
}, | |
), | |
CupertinoActionSheetAction( | |
child: const Text('π No'), | |
onPressed: () { | |
Navigator.pop(context, 'π No'); | |
}, | |
), | |
CupertinoActionSheetAction( | |
child: const Text("π Can't say"), | |
onPressed: () { | |
Navigator.pop(context, "π Can't say"); | |
}, | |
), | |
CupertinoActionSheetAction( | |
child: const Text("π Decide in next post"), | |
onPressed: () { | |
Navigator.pop(context, "π Decide in next post"); | |
}, | |
), | |
], | |
cancelButton: CupertinoActionSheetAction( | |
child: const Text('Cancel'), | |
isDefaultAction: true, | |
onPressed: () { | |
Navigator.pop(context, 'Cancel'); | |
}, | |
)), | |
); | |
} | |
), | |
SizedBox( | |
height: 20, | |
), | |
new CupertinoAlertDialog( | |
title: new Text("Dialog Title"), | |
content: new Text("This is my content"), | |
actions: <Widget>[ | |
CupertinoDialogAction( | |
isDefaultAction: true, | |
child: Text("Yes"), | |
), | |
CupertinoDialogAction( | |
child: Text("No"), | |
) | |
], | |
), | |
] | |
), | |
); | |
} | |
), | |
); | |
} | |
void containerForSheet<T>({BuildContext context, Widget child}) { | |
showCupertinoModalPopup<T>( | |
context: context, | |
builder: (BuildContext context) => child, | |
).then<void>((T value) { | |
Scaffold.of(context).showSnackBar(new SnackBar( | |
content: new Text('You clicked $value'), | |
duration: Duration(milliseconds: 800), | |
)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment