From 80217687ea4745f86499b5416bc74ba9ee9ba854 Mon Sep 17 00:00:00 2001 From: haolun1996 <33619117+haolun1996@users.noreply.github.com> Date: Wed, 8 Feb 2023 13:06:52 +0800 Subject: [PATCH] disable pop up menu when pass in empty array --- .../screen/feature/column_menu_screen.dart | 20 +++++++++++++ lib/src/helper/show_column_menu.dart | 30 +++++++++++-------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/demo/lib/screen/feature/column_menu_screen.dart b/demo/lib/screen/feature/column_menu_screen.dart index ba46552f4..53027841b 100644 --- a/demo/lib/screen/feature/column_menu_screen.dart +++ b/demo/lib/screen/feature/column_menu_screen.dart @@ -113,3 +113,23 @@ enum _UserColumnMenuItem { moveNext, movePrevious, } + +/// [CustomColumnMenu] override buildMenuItems with returnning empty array to make that pop up menu won't trigger +class CustomColumnMenu implements PlutoColumnMenuDelegate { + @override + List buildMenuItems({ + required PlutoGridStateManager stateManager, + required PlutoColumn column, + }) { + return []; + } + + @override + void onSelected({ + required BuildContext context, + required PlutoGridStateManager stateManager, + required PlutoColumn column, + required bool mounted, + required selected, + }) {} +} diff --git a/lib/src/helper/show_column_menu.dart b/lib/src/helper/show_column_menu.dart index 878eab54c..b59581a96 100644 --- a/lib/src/helper/show_column_menu.dart +++ b/lib/src/helper/show_column_menu.dart @@ -84,18 +84,24 @@ Future? showColumnMenu({ final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; - return showMenu( - context: context, - color: backgroundColor, - position: RelativeRect.fromLTRB( - position.dx, - position.dy, - position.dx + overlay.size.width, - position.dy + overlay.size.height, - ), - items: items, - useRootNavigator: true, - ); + // Add isNotEmpty checking here so that won't pop up menu + // when can pass in empty array on buildMenuItems on class PlutoColumnMenuDelegate + // refer to ColumnMenuScreen class + if (items.isNotEmpty){ + return showMenu( + context: context, + color: backgroundColor, + position: RelativeRect.fromLTRB( + position.dx, + position.dy, + position.dx + overlay.size.width, + position.dy + overlay.size.height, + ), + items: items, + useRootNavigator: true, + ); + } + } List> _getDefaultColumnMenuItems({