From 5c710f5019c4922588a8c85ae5e41f690bbd03da Mon Sep 17 00:00:00 2001 From: laiiihz Date: Tue, 22 Dec 2020 14:19:24 +0800 Subject: [PATCH] update pop menu --- example/lib/example_pop_up_menu.dart | 1 + lib/pop_up_menu/pop_up_menu.dart | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/example/lib/example_pop_up_menu.dart b/example/lib/example_pop_up_menu.dart index 807b1f9..302ff6c 100644 --- a/example/lib/example_pop_up_menu.dart +++ b/example/lib/example_pop_up_menu.dart @@ -15,6 +15,7 @@ class _ExamplePopUpMenuState extends State { title: 'PopUpMenu', body: ListView( children: [ + SizedBox(height: 500), ListTile( title: 'PopUpMenu'.text, trailing: Builder( diff --git a/lib/pop_up_menu/pop_up_menu.dart b/lib/pop_up_menu/pop_up_menu.dart index 8e13a4c..225ab89 100644 --- a/lib/pop_up_menu/pop_up_menu.dart +++ b/lib/pop_up_menu/pop_up_menu.dart @@ -1,4 +1,3 @@ -import 'package:ansu_ui/utils/screen_adapter.dart'; import 'package:ansu_ui/extension/num_extension.dart'; import 'package:flutter/material.dart'; @@ -17,15 +16,17 @@ Future showASPopUpMenu({ T initValue, }) async { final RenderBox renderBox = context.findRenderObject(); - Offset offset = renderBox.localToGlobal(Offset.zero); + Size size = renderBox.size; return await showMenu( context: context, initialValue: initValue, - position: RelativeRect.fromLTRB( - offset.dx, - offset.dy, - screenWidth, - screenHeight, + position: RelativeRect.fromRect( + Rect.fromPoints( + renderBox.localToGlobal(Offset.zero, + ancestor: Overlay.of(context).context.findRenderObject()), + renderBox.localToGlobal(size.bottomRight(Offset.zero)), + ), + Offset.zero & Overlay.of(context).context.size, ), items: items, shape: RoundedRectangleBorder(borderRadius: 10.radius),