Skip to content

Instantly share code, notes, and snippets.

@stefanasandei
Created December 22, 2019 16:49
Show Gist options
  • Save stefanasandei/13d5db9ebedf5e75c3493070f70325cb to your computer and use it in GitHub Desktop.
Save stefanasandei/13d5db9ebedf5e75c3493070f70325cb to your computer and use it in GitHub Desktop.
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