-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repositioning of context menu when the content expands or contracts #5
Comments
For people comming after me, I can recommend to use the example classesclass ContextMenu extends StatelessWidget {
const ContextMenu(
{Key? key, this.menuBuilder, this.secondaryTap, required this.child})
: super(key: key);
final List<Widget> Function(BuildContext)? menuBuilder;
final VoidCallback? secondaryTap;
final Widget child;
void showContextMenu(BuildContext context, Offset globalPosition) {
final RenderBox? overlay =
Overlay.of(context)?.context.findRenderObject() as RenderBox?;
showMenu<void>(
context: context,
position: RelativeRect.fromRect(
globalPosition & const Size(40, 40), // smaller rect, the touch area
Offset.zero &
(overlay?.size ?? Size.zero) // Bigger rect, the entire screen
),
items: (menuBuilder?.call(context) ?? [])
.map((e) => _CustomPopupEntry(child: e))
.toList());
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onLongPressDown: (d) =>
showContextMenu(context, d.globalPosition),
onSecondaryTapDown: (d) =>
showContextMenu(context, d.globalPosition),
child: child);
}
} class _CustomPopupEntry extends PopupMenuEntry<void> {
_CustomPopupEntry({Key? key, required this.child}) : super(key: key);
final Widget child;
@override
__CustomPopupEntryState createState() => __CustomPopupEntryState();
@override
final double height = 100;
// height doesn't matter, as long as we are not giving
// initialValue to showMenu().
@override
bool represents(void value) {
return true;
// doesn't matter, as I use [PopupMenuEntry<void>]
}
}
class __CustomPopupEntryState extends State<_CustomPopupEntry> {
@override
Widget build(BuildContext context) {
return widget.child;
}
} |
is there any update on this problem? @gskinner |
Thanks for the report, we don't currently test context menus that change size after opening. It's a bit tricky, as when widgets expand there are situation where you will have no choice but to reposition the widget, otherwise content will be clipped. In some cases the repositioning might be the desired behavior...Maybe we can add a As for the rest, |
Navigator.pop(context);
would close the context menu, but this does not seem to be the case.cardBuilder
ofContextMenuOverlay
does not seem to work. (It is to note, that myContextMenuOverlay
is placed under the MaterialApp as of ContextMenuOverlay does not work as shown in example #4.Regarding 1, here is an explanation video:
context_menu.mp4
The text was updated successfully, but these errors were encountered: