From 32257c3dc478d51bf5e7cb8b92a9cfd899847713 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Wed, 27 Dec 2023 10:05:21 +0100 Subject: [PATCH] Simplify menu builder --- app/lib/views/app_bar.dart | 9 ++------- app/lib/views/files/view.dart | 5 ++--- app/lib/views/home.dart | 5 ++--- app/lib/views/property.dart | 6 +----- app/lib/views/toolbar/label.dart | 5 +---- app/lib/widgets/context_menu.dart | 7 ++----- app/lib/widgets/window.dart | 17 +++-------------- app/pubspec.lock | 8 ++++---- app/pubspec.yaml | 2 +- 9 files changed, 18 insertions(+), 46 deletions(-) diff --git a/app/lib/views/app_bar.dart b/app/lib/views/app_bar.dart index d07cf86e00a3..b92815785f78 100644 --- a/app/lib/views/app_bar.dart +++ b/app/lib/views/app_bar.dart @@ -18,6 +18,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:go_router/go_router.dart'; +import 'package:material_leap/material_leap.dart'; import 'package:networker/networker.dart'; import 'package:phosphor_flutter/phosphor_flutter.dart'; @@ -584,13 +585,7 @@ class _MainPopupMenu extends StatelessWidget { ), tooltip: AppLocalizations.of(context).actions, isSelected: controller.isOpen, - onPressed: () { - if (controller.isOpen) { - controller.close(); - } else { - controller.open(); - } - }, + onPressed: controller.toggle, ), ), ), diff --git a/app/lib/views/files/view.dart b/app/lib/views/files/view.dart index acf54242022a..b06c9f7d17f3 100644 --- a/app/lib/views/files/view.dart +++ b/app/lib/views/files/view.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:go_router/go_router.dart'; +import 'package:material_leap/material_leap.dart'; import 'package:phosphor_flutter/phosphor_flutter.dart'; import '../../api/file_system/file_system.dart'; @@ -349,9 +350,7 @@ class FilesViewState extends State { builder: (context, controller, child) => FloatingActionButton.small( heroTag: null, - onPressed: () => controller.isOpen - ? controller.close() - : controller.open(), + onPressed: controller.toggle, tooltip: AppLocalizations.of(context).create, child: const PhosphorIcon(PhosphorIconsLight.plus), ), diff --git a/app/lib/views/home.dart b/app/lib/views/home.dart index c59d9d02cf6a..24b0d55f9c62 100644 --- a/app/lib/views/home.dart +++ b/app/lib/views/home.dart @@ -9,6 +9,7 @@ import 'package:butterfly_api/butterfly_api.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:material_leap/material_leap.dart'; import 'package:phosphor_flutter/phosphor_flutter.dart'; import '../main.dart'; @@ -33,11 +34,9 @@ String _getLocalizedNameOfBannerVisibility( Widget _getBannerVisibilityWidget( BuildContext context, ButterflySettings settings) { return MenuAnchor( - builder: (context, controller, child) => IconButton( + builder: defaultMenuButton( tooltip: AppLocalizations.of(context).visibility, icon: PhosphorIcon(_getIconOfBannerVisibility(settings.bannerVisibility)), - onPressed: () => - controller.isOpen ? controller.close() : controller.open(), ), menuChildren: BannerVisibility.values .map( diff --git a/app/lib/views/property.dart b/app/lib/views/property.dart index eb7cb69b387a..9124fc0a1fb4 100644 --- a/app/lib/views/property.dart +++ b/app/lib/views/property.dart @@ -150,8 +150,7 @@ class _PropertyViewState extends State ? icon : MenuAnchor( controller: controller, - builder: (context, controller, child) => - IconButton.filledTonal( + builder: defaultFilledMenuButton( icon: Row( children: [ icon, @@ -167,9 +166,6 @@ class _PropertyViewState extends State ), tooltip: AppLocalizations.of(context).icon, - onPressed: () => controller.isOpen - ? controller.close() - : controller.open(), isSelected: controller.isOpen, ), menuChildren: menuChildren, diff --git a/app/lib/views/toolbar/label.dart b/app/lib/views/toolbar/label.dart index 074c562aa665..26726d0b206e 100644 --- a/app/lib/views/toolbar/label.dart +++ b/app/lib/views/toolbar/label.dart @@ -247,14 +247,11 @@ class _LabelToolbarViewState extends State { value.tool.copyWith(mode: e)))), ) .toList(), - builder: (context, controller, child) => IconButton( + builder: defaultMenuButton( icon: PhosphorIcon( mode.icon(PhosphorIconsStyle.light)), tooltip: AppLocalizations.of(context).chooseLabelMode, - onPressed: () => controller.isOpen - ? controller.close() - : controller.open(), ), ), if (value is TextContext) ...[ diff --git a/app/lib/widgets/context_menu.dart b/app/lib/widgets/context_menu.dart index ec65e4a2a50a..7724ed8ea76c 100644 --- a/app/lib/widgets/context_menu.dart +++ b/app/lib/widgets/context_menu.dart @@ -5,6 +5,7 @@ import 'package:animations/animations.dart'; import 'package:butterfly/cubits/settings.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:material_leap/material_leap.dart'; typedef ContextMenuBuilder = List Function( BuildContext context); @@ -132,11 +133,7 @@ class _ContextMenuState extends State ? MenuAnchor( menuChildren: item.children, builder: (context, controller, child) => - buildItemWidget( - () => controller.isOpen - ? controller.close() - : controller.open(), - ), + buildItemWidget(controller.toggle), ) : SubmenuButton( menuChildren: item.children, diff --git a/app/lib/widgets/window.dart b/app/lib/widgets/window.dart index 805c95a9be05..ddd2c4882abb 100644 --- a/app/lib/widgets/window.dart +++ b/app/lib/widgets/window.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:material_leap/material_leap.dart'; import 'package:phosphor_flutter/phosphor_flutter.dart'; import 'package:window_manager/window_manager.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -180,6 +181,8 @@ class _WindowButtonsState extends State with WindowListener { MenuAnchor( builder: (context, controller, child) => GestureDetector( + onLongPress: controller.toggle, + onSecondaryTap: controller.toggle, child: IconButton( tooltip: maximized ? AppLocalizations.of(context).restore @@ -194,20 +197,6 @@ class _WindowButtonsState extends State with WindowListener { ? windowManager.unmaximize() : windowManager.maximize(), ), - onLongPress: () async { - if (controller.isOpen) { - controller.close(); - } else { - controller.open(); - } - }, - onSecondaryTap: () async { - if (controller.isOpen) { - controller.close(); - } else { - controller.open(); - } - }, ), menuChildren: [ MenuItemButton( diff --git a/app/pubspec.lock b/app/pubspec.lock index 37e4354b7d1b..9b470cebabba 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -308,8 +308,8 @@ packages: dependency: transitive description: path: "packages/dart_leap" - ref: "47a223756447b027f6e0d2f7e537f4a1ca4bbce7" - resolved-ref: "47a223756447b027f6e0d2f7e537f4a1ca4bbce7" + ref: "992f8062618ef1e78ee92efc7a709eb0d476e1d0" + resolved-ref: "992f8062618ef1e78ee92efc7a709eb0d476e1d0" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" @@ -796,8 +796,8 @@ packages: dependency: "direct main" description: path: "packages/material_leap" - ref: "723027ec49a65f68708e23336348695cf2bf79bb" - resolved-ref: "723027ec49a65f68708e23336348695cf2bf79bb" + ref: "524e4189e7b36bda022b6b153778e701a74f4dc1" + resolved-ref: "524e4189e7b36bda022b6b153778e701a74f4dc1" url: "https://github.com/LinwoodDev/dart_pkgs.git" source: git version: "0.0.1" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index c6f922ffe8dc..e68509677a39 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -70,7 +70,7 @@ dependencies: material_leap: git: url: https://github.com/LinwoodDev/dart_pkgs.git - ref: 723027ec49a65f68708e23336348695cf2bf79bb + ref: 524e4189e7b36bda022b6b153778e701a74f4dc1 path: packages/material_leap lw_sysinfo: git: