Skip to content

Instantly share code, notes, and snippets.

@kvadrakot
Last active November 25, 2020 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvadrakot/f5fe0e3ee2d776303c077216dea61198 to your computer and use it in GitHub Desktop.
Save kvadrakot/f5fe0e3ee2d776303c077216dea61198 to your computer and use it in GitHub Desktop.
class PopMenuWidget extends StatefulWidget {
Channel channel;
VoidCallback onDelete;
PopMenuWidget(BuildContext context, this.channel, onDelete);
@override
_PopMenuWidgetState createState() => _PopMenuWidgetState();
}
class _PopMenuWidgetState extends State<PopMenuWidget> {
List<bool> isSelected = [true, false, false];
@override
Widget build(BuildContext context) => PopupMenuButton<int>(
onSelected: (result) {
//View
if (result == 0) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NativePage(
channel: widget.channel,
)),
);
}
//Edit
if (result == 1) {
_showMaterialDialog() {
showDialog(
context: context,
builder: (_) => new AlertDialog(
title: Column(
children: [
new Text("${widget.channel.Name}"),
],
),
content: Column(
children: [
new Text("Edit"),
Padding(
padding: const EdgeInsets.all(8.0),
child: ToggleSwitch(
minWidth: 90.0,
initialLabelIndex: 1,
cornerRadius: 20.0,
activeFgColor: Colors.white,
inactiveBgColor: Colors.grey,
inactiveFgColor: Colors.white,
labels: ['Male', 'Female'],
icons: [
Icons.check_circle_outline,
Icons.highlight_off
],
activeBgColors: [Colors.green, Colors.pink],
onToggle: (index) {
print('switched to: $index');
},
),
),
],
),
actions: <Widget>[
FlatButton(
child: Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
));
}
_showMaterialDialog();
}
//Delete
if (result == 2) {
widget.onDelete();
}
},
itemBuilder: (context) => [
PopupMenuItem(
value: 0,
child: Row(
children: <Widget>[
Icon(
Icons.remove_red_eye_rounded,
color: Colors.black38,
),
Text(' View', style: TextStyle(color: Colors.black38)),
],
),
),
PopupMenuItem(
value: 1,
child: Row(
children: <Widget>[
Icon(
Icons.create,
color: Colors.black38,
),
Text(' Edit',
style: TextStyle(color: Colors.black38)),
],
),
),
PopupMenuItem(
value: 2,
child: Row(
children: <Widget>[
Icon(
Icons.delete,
color: Colors.black38,
),
Text(' Delete', style: TextStyle(color: Colors.black38)),
],
),
),
],
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment