I need to make a popup menu kind of button. Is there any way to make a pop up menu floating action button,this is my desired view
Displays a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. If we focus on an Application, We can see in every Application there is a Pop Up Menu button that will do some work.
You can use flutter speed dial package. Visit - https://pub.dev/packages/flutter_speed_dial . And here is a youtube video - https://www.youtube.com/watch?v=1FmATI4rOBc
Your answer is PopupMenuItem class, which will help you get the desirable result.
PLEASE NOTE: I have just demonstrated how to use, and with what code, you achieve the result. You can anyways, play with it, and get your desirable result.
CODE SNIPPET FOR CREATING A POPUP MENU ITEM
PopupMenuButton<Choice>(
itemBuilder: (context) => [
PopupMenuItem()
],
icon: Icon(),
offset: Offset()
)
CODE FOR REFERENCE
class _MyHomePageState extends State<MyHomePage> {
Widget _offsetPopup() => PopupMenuButton<int>(
itemBuilder: (context) => [
PopupMenuItem(
value: 1,
child: Text(
"Flutter Open",
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.w700),
),
),
PopupMenuItem(
value: 2,
child: Text(
"Flutter Tutorial",
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.w700),
),
),
],
icon: Container(
height: double.infinity,
width: double.infinity,
decoration: ShapeDecoration(
color: Colors.blue,
shape: StadiumBorder(
side: BorderSide(color: Colors.white, width: 2),
)
),
//child: Icon(Icons.menu, color: Colors.white), <-- You can give your icon here
)
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: EdgeInsets.only(right: 10.0, bottom: 10.0),
child: Align(
alignment: Alignment.bottomRight,
child: Container(
height: 80.0,
width: 80.0,
child: _offsetPopup()
)
)
)
);
}
}
The above will give you this result:
PRO-TIP
You can play around with Offset()
to decide the position of your PopupMenuItems
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With