Created
September 23, 2021 13:30
-
-
Save loonix/c94e6d41e0a519109c6d95005064f0a4 to your computer and use it in GitHub Desktop.
[Flutter] Long Press menu widget
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
var _tapPosition; | |
void _showCustomMenu() { | |
var overlay = Overlay.of(context)!.context.findRenderObject() as RenderBox; | |
showMenu( | |
context: context, | |
items: <PopupMenuEntry<int>>[PlusMinusEntry()], | |
position: RelativeRect.fromRect( | |
_tapPosition & const Size(40, 40), // smaller rect, the touch area | |
Offset.zero & overlay.size // Bigger rect, the entire screen | |
)); | |
} | |
void _storePosition(TapDownDetails details) { | |
_tapPosition = details.globalPosition; | |
} | |
return GestureDetector( | |
// This does not give the tap position ... | |
onLongPress: _showCustomMenu, | |
// Have to remember it on tap-down. | |
onTapDown: _storePosition, | |
child: (....) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment