答案 0 :(得分:0)
尝试一下:
PopupMenuButton<MenuItems>(
child: Row(
children: [
Text('Show Menu'),
Icon(
Icons.expand_more,
color: Colors.grey,
),
],
),
onSelected: (MenuItems result) {
setState(() {
selection = result;
});
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<MenuItems>>[
PopupMenuItem<MenuItems>(
value: MenuItems.one,
child: Row(
children: [
MenuItems.one == selectedItem
? Row(
children: [
Container(
width: 3,
height: 16,
color: Colors.red,
),
SizedBox(
width: 8,
),
],
)
: Container(),
Text(
'One',
style: TextStyle(
color: (MenuItems.one == selectedItem)
? Colors.red
: null,
),
),
],
),
),
PopupMenuItem<MenuItems>(
value: MenuItems.two,
child: Row(
children: [
MenuItems.two == selectedItem
? Row(
children: [
Container(
width: 3,
height: 16,
color: Colors.red,
),
SizedBox(
width: 8,
),
],
)
: Container(),
Text(
'Two',
style: TextStyle(
color: (MenuItems.two == selectedItem)
? Colors.red
: null,
),
),
],
),
),
PopupMenuItem<MenuItems>(
value: MenuItems.three,
child: Row(
children: [
MenuItems.three == selectedItem
? Row(
children: [
Container(
width: 3,
height: 16,
color: Colors.red,
),
SizedBox(
width: 8,
),
],
)
: Container(),
Text(
'Three',
style: TextStyle(
color: (MenuItems.three == selectedItem)
? Colors.red
: null,
),
),
],
),
),
],
),
],
),