Skip to content

Instantly share code, notes, and snippets.

@dragneelfps
Last active May 19, 2019 03:20
Show Gist options
  • Save dragneelfps/56668e2bbcf6ddc2f9eb93b928fae281 to your computer and use it in GitHub Desktop.
Save dragneelfps/56668e2bbcf6ddc2f9eb93b928fae281 to your computer and use it in GitHub Desktop.
Show nested menu for PopupMenuButon
Future<T> showNestedMenu<T>(
{@required BuildContext context,
@required GlobalKey<State> popupButtonKey,
@required List<PopupMenuEntry<T>> items}) async {
final RenderBox popupButtonObject =
popupButtonKey.currentContext.findRenderObject();
final RenderBox overlay = Overlay.of(context).context.findRenderObject();
final position = RelativeRect.fromRect(
Rect.fromPoints(
popupButtonObject.localToGlobal(Offset.zero, ancestor: overlay),
popupButtonObject.localToGlobal(
popupButtonObject.size.bottomRight(Offset.zero),
ancestor: overlay)),
Offset.zero & overlay.size);
return showMenu(context: context, items: items, position: position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment