-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e8f0a8
commit 9577dbd
Showing
4 changed files
with
142 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
enum SampleItem { itemOne, itemTwo, itemThree } | ||
|
||
class CustomPopMenuButton extends StatefulWidget { | ||
const CustomPopMenuButton({super.key}); | ||
|
||
@override | ||
State<CustomPopMenuButton> createState() => _CustomPopMenuButtonState(); | ||
} | ||
|
||
class _CustomPopMenuButtonState extends State<CustomPopMenuButton> { | ||
SampleItem? selectedMenu; | ||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
child: PopupMenuButton<SampleItem>( | ||
initialValue: selectedMenu, | ||
// Callback that sets the selected popup menu item. | ||
onSelected: (SampleItem item) { | ||
setState(() { | ||
selectedMenu = item; | ||
}); | ||
}, | ||
itemBuilder: (BuildContext context) => <PopupMenuEntry<SampleItem>>[ | ||
const PopupMenuItem<SampleItem>( | ||
value: SampleItem.itemOne, | ||
child: Text('Item 1'), | ||
), | ||
const PopupMenuItem<SampleItem>( | ||
value: SampleItem.itemTwo, | ||
child: Text('Item 2'), | ||
), | ||
const PopupMenuItem<SampleItem>( | ||
value: SampleItem.itemThree, | ||
child: Text('Item 3'), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |