diff --git a/lib/widgets/editable_tab_bar.dart b/lib/widgets/editable_tab_bar.dart index 9cd116fd..b05a01e1 100644 --- a/lib/widgets/editable_tab_bar.dart +++ b/lib/widgets/editable_tab_bar.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:contextmenu/contextmenu.dart'; +import 'package:flutter_context_menu/flutter_context_menu.dart'; import 'package:provider/provider.dart'; import 'package:transitioned_indexed_stack/transitioned_indexed_stack.dart'; @@ -119,39 +119,28 @@ class EditableTabBar extends StatelessWidget { shrinkWrap: true, itemCount: tabData.length, itemBuilder: (context, index) { - return ContextMenuArea( - builder: (context) => [ - ListTile( - enabled: false, - dense: true, - visualDensity: const VisualDensity( - horizontal: 0.0, vertical: -4.0), - title: Center(child: Text(tabData[index].name)), - ), - ListTile( - dense: true, - visualDensity: const VisualDensity( - horizontal: 0.0, vertical: -4.0), - leading: const Icon( - Icons.drive_file_rename_outline_outlined), - title: const Text('Rename'), - onTap: () { - Navigator.of(context).pop(); - renameTab(context, index); - }, - ), - ListTile( - dense: true, - visualDensity: const VisualDensity( - horizontal: 0.0, vertical: -4.0), - leading: const Icon(Icons.close), - title: const Text('Close'), - onTap: () { - Navigator.of(context).pop(); - closeTab(index); - }, - ), - ], + return ContextMenuRegion( + contextMenu: ContextMenu( + borderRadius: BorderRadius.circular(5.0), + padding: const EdgeInsets.all(4.0), + entries: [ + MenuHeader( + text: tabData[index].name, + disableUppercase: true, + ), + const MenuDivider(), + MenuItem( + label: 'Rename', + icon: Icons.drive_file_rename_outline_outlined, + onSelected: () => renameTab(context, index), + ), + MenuItem( + label: 'Close', + icon: Icons.close, + onSelected: () => closeTab(index), + ), + ], + ), child: GestureDetector( onTap: () { onTabChanged.call(index); diff --git a/lib/widgets/tab_grid.dart b/lib/widgets/tab_grid.dart index ca7b991e..db278b04 100644 --- a/lib/widgets/tab_grid.dart +++ b/lib/widgets/tab_grid.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:contextmenu/contextmenu.dart'; import 'package:dot_cast/dot_cast.dart'; +import 'package:flutter_context_menu/flutter_context_menu.dart'; import 'package:provider/provider.dart'; import 'package:elastic_dashboard/services/nt4_connection.dart'; @@ -776,39 +776,57 @@ class TabGrid extends StatelessWidget { } } + ContextMenu menu = ContextMenu( + borderRadius: BorderRadius.circular(5.0), + padding: const EdgeInsets.all(4.0), + entries: [ + MenuHeader( + text: container.title ?? '', + disableUppercase: true, + ), + const MenuDivider(), + MenuItem( + label: 'Edit Properties', + icon: Icons.edit_outlined, + onSelected: () { + print('Edit properties!'); + }, + ), + MenuItem( + label: 'Remove', + icon: Icons.delete_outlined, + onSelected: () { + print('Remove!'); + }), + ], + ); + dashboardWidgets.add( - ContextMenuArea( - builder: (context) => [ - ListTile( - enabled: false, - dense: true, - visualDensity: - const VisualDensity(horizontal: 0.0, vertical: -4.0), - title: Center(child: Text(container.title ?? '')), - ), - ListTile( - dense: true, - visualDensity: - const VisualDensity(horizontal: 0.0, vertical: -4.0), - leading: const Icon(Icons.edit_outlined), - title: const Text('Edit Properties'), - onTap: () { - Navigator.of(context).pop(); - container.showEditProperties(context); - }, - ), - ListTile( - dense: true, - visualDensity: - const VisualDensity(horizontal: 0.0, vertical: -4.0), - leading: const Icon(Icons.delete_outlined), - title: const Text('Remove'), - onTap: () { - Navigator.of(context).pop(); - removeWidget(container); - }, - ), - ], + ContextMenuRegion( + contextMenu: ContextMenu( + borderRadius: BorderRadius.circular(5.0), + padding: const EdgeInsets.all(4.0), + entries: [ + MenuHeader( + text: container.title ?? '', + disableUppercase: true, + ), + const MenuDivider(), + MenuItem( + label: 'Edit Properties', + icon: Icons.edit_outlined, + onSelected: () { + container.showEditProperties(context); + }, + ), + MenuItem( + label: 'Remove', + icon: Icons.delete_outlined, + onSelected: () { + removeWidget(container); + }), + ], + ), child: ChangeNotifierProvider( create: (context) => WidgetContainerModel(), child: container, @@ -873,57 +891,47 @@ class TabGrid extends StatelessWidget { ); } - defaultMenuBuilder(context) => [ - ListTile( - dense: true, - visualDensity: const VisualDensity(horizontal: 0.0, vertical: -4.0), - leading: const Icon(Icons.add), - title: const Text('Add Widget'), - onTap: () { - Navigator.of(context).pop(); - onAddWidgetPressed?.call(); - }, - ), - ListTile( - dense: true, - visualDensity: const VisualDensity(horizontal: 0.0, vertical: -4.0), - leading: const Icon(Icons.clear), - title: const Text('Clear Layout'), - onTap: () { - Navigator.of(context).pop(); - clearWidgets(); - }, - ), - ]; - return GestureDetector( - // Needed to prevent 2 context menus from showing at the same time behavior: HitTestBehavior.translucent, onSecondaryTapDown: (details) { - if (!isValidLocation(Rect.fromLTWH( - details.localPosition.dx, details.localPosition.dy, 0, 0))) { - return; - } - showContextMenu( - details.globalPosition, - context, - defaultMenuBuilder, - 8.0, - 320.0, + ContextMenu contextMenu = ContextMenu( + position: details.globalPosition, + borderRadius: BorderRadius.circular(5.0), + padding: const EdgeInsets.all(4.0), + entries: [ + MenuItem( + label: 'Add Widget', + icon: Icons.add, + onSelected: () => onAddWidgetPressed?.call(), + ), + MenuItem( + label: 'Clear Layout', + icon: Icons.clear, + onSelected: () => clearWidgets(), + ), + ], ); + contextMenu.show(context); }, onLongPressStart: (details) { - if (!isValidLocation(Rect.fromLTWH( - details.localPosition.dx, details.localPosition.dy, 0, 0))) { - return; - } - showContextMenu( - details.globalPosition, - context, - defaultMenuBuilder, - 8.0, - 320.0, + ContextMenu contextMenu = ContextMenu( + position: details.globalPosition, + borderRadius: BorderRadius.circular(5.0), + padding: const EdgeInsets.all(4.0), + entries: [ + MenuItem( + label: 'Add Widget', + icon: Icons.add, + onSelected: () => onAddWidgetPressed?.call(), + ), + MenuItem( + label: 'Clear Layout', + icon: Icons.clear, + onSelected: () => clearWidgets(), + ), + ], ); + contextMenu.show(context); }, child: Stack( children: [ diff --git a/pubspec.lock b/pubspec.lock index a43983f6..ae5868a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,14 +9,6 @@ packages: url: "https://pub.dev" source: hosted version: "64.0.0" - after_layout: - dependency: transitive - description: - name: after_layout - sha256: "95a1cb2ca1464f44f14769329fbf15987d20ab6c88f8fc5d359bd362be625f29" - url: "https://pub.dev" - source: hosted - version: "1.2.0" analyzer: dependency: transitive description: @@ -193,14 +185,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" - contextmenu: - dependency: "direct main" - description: - name: contextmenu - sha256: e0c7d60e2fc9f316f5b03f5fe2c0f977d65125345d1a1f77eea02be612e32d0c - url: "https://pub.dev" - source: hosted - version: "3.0.0" convert: dependency: transitive description: @@ -265,6 +249,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.2" + equatable: + dependency: transitive + description: + name: equatable + sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + url: "https://pub.dev" + source: hosted + version: "2.0.5" fake_async: dependency: transitive description: @@ -382,6 +374,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.3" + flutter_context_menu: + dependency: "direct main" + description: + name: flutter_context_menu + sha256: "9f220a8fa0290c68e38000d6d62a0dc4555d490c15a5bd856a6e6d255d81b8dc" + url: "https://pub.dev" + source: hosted + version: "0.1.3" flutter_fancy_tree_view: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 3c3f677e..1dad4cd2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,6 @@ environment: dependencies: animations: ^2.0.7 collection: ^1.17.1 - contextmenu: ^3.0.0 dot_cast: ^1.2.0 dropdown_button2: ^2.3.9 elegant_notification: ^1.11.0 @@ -18,6 +17,7 @@ dependencies: sdk: flutter flutter_box_transform: ^0.4.2 flutter_colorpicker: ^1.0.3 + flutter_context_menu: ^0.1.3 flutter_fancy_tree_view: ^1.1.1 flutter_hooks: ^0.20.0 flutter_launcher_icons: ^0.13.1