Skip to content

Commit

Permalink
Simplify menu builder
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Dec 27, 2023
1 parent 123bcd4 commit 32257c3
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 46 deletions.
9 changes: 2 additions & 7 deletions app/lib/views/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
),
),
),
Expand Down
5 changes: 2 additions & 3 deletions app/lib/views/files/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -349,9 +350,7 @@ class FilesViewState extends State<FilesView> {
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),
),
Expand Down
5 changes: 2 additions & 3 deletions app/lib/views/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand Down
6 changes: 1 addition & 5 deletions app/lib/views/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ class _PropertyViewState extends State<PropertyView>
? icon
: MenuAnchor(
controller: controller,
builder: (context, controller, child) =>
IconButton.filledTonal(
builder: defaultFilledMenuButton(
icon: Row(
children: [
icon,
Expand All @@ -167,9 +166,6 @@ class _PropertyViewState extends State<PropertyView>
),
tooltip:
AppLocalizations.of(context).icon,
onPressed: () => controller.isOpen
? controller.close()
: controller.open(),
isSelected: controller.isOpen,
),
menuChildren: menuChildren,
Expand Down
5 changes: 1 addition & 4 deletions app/lib/views/toolbar/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,11 @@ class _LabelToolbarViewState extends State<LabelToolbarView> {
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) ...[
Expand Down
7 changes: 2 additions & 5 deletions app/lib/widgets/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextMenuEntry> Function(
BuildContext context);
Expand Down Expand Up @@ -132,11 +133,7 @@ class _ContextMenuState extends State<ContextMenu>
? MenuAnchor(
menuChildren: item.children,
builder: (context, controller, child) =>
buildItemWidget(
() => controller.isOpen
? controller.close()
: controller.open(),
),
buildItemWidget(controller.toggle),
)
: SubmenuButton(
menuChildren: item.children,
Expand Down
17 changes: 3 additions & 14 deletions app/lib/widgets/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -180,6 +181,8 @@ class _WindowButtonsState extends State<WindowButtons> with WindowListener {
MenuAnchor(
builder: (context, controller, child) =>
GestureDetector(
onLongPress: controller.toggle,
onSecondaryTap: controller.toggle,
child: IconButton(
tooltip: maximized
? AppLocalizations.of(context).restore
Expand All @@ -194,20 +197,6 @@ class _WindowButtonsState extends State<WindowButtons> 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(
Expand Down
8 changes: 4 additions & 4 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 32257c3

Please sign in to comment.