I don't use PopupMenuButton.
Because in my case, showMenu would be more appropriate.
onLongPress: () => _onRoomLongPressed(context, _tappedPosition, model, room),
void _onRoomLongPressed(BuildContext context, Offset tappedPosition,
RoomsModel model, Room room) {
final RenderBox overlay = Overlay.of(context).context.findRenderObject();
showMenu(
context: context,
position: RelativeRect.fromRect(
tappedPosition & Size.zero, Offset.zero & overlay.size),
items: [
PopupMenuItem(
value: 'delete',
child: Text('delete'),
),
],
).then((String value) {
switch (value) {
case 'delete':
model.remove(room);
break;
}
});
}
Don't change the theme of MaterialApp()
.
I expect that the background color of PopupMenuItem
to be white and the Text
color black.