From da18e69258c1a1133db5a7be3204b616cf084cc2 Mon Sep 17 00:00:00 2001 From: csf Date: Thu, 13 Oct 2022 20:22:11 +0900 Subject: [PATCH] update file transfer pop menu style / fixed file name width --- flutter/lib/common/widgets/peer_card.dart | 7 -- .../lib/desktop/pages/file_manager_page.dart | 82 ++++++++++++------- flutter/lib/desktop/widgets/popup_menu.dart | 8 ++ 3 files changed, 59 insertions(+), 38 deletions(-) diff --git a/flutter/lib/common/widgets/peer_card.dart b/flutter/lib/common/widgets/peer_card.dart index 19d28513c..c99cf2e68 100644 --- a/flutter/lib/common/widgets/peer_card.dart +++ b/flutter/lib/common/widgets/peer_card.dart @@ -12,13 +12,6 @@ import '../../models/platform_model.dart'; import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu; import '../../desktop/widgets/popup_menu.dart'; -class CustomPopupMenuTheme { - static const Color commonColor = MyTheme.accent; - // kMinInteractiveDimension - static const double height = 20.0; - static const double dividerHeight = 3.0; -} - typedef PopupMenuEntryBuilder = Future>> Function(BuildContext); diff --git a/flutter/lib/desktop/pages/file_manager_page.dart b/flutter/lib/desktop/pages/file_manager_page.dart index 19a7a3e56..f6fae1e31 100644 --- a/flutter/lib/desktop/pages/file_manager_page.dart +++ b/flutter/lib/desktop/pages/file_manager_page.dart @@ -9,10 +9,13 @@ import 'package:flutter_hbb/models/file_model.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; import 'package:wakelock/wakelock.dart'; +import '../../consts.dart'; +import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu; import '../../common.dart'; import '../../models/model.dart'; import '../../models/platform_model.dart'; +import '../widgets/popup_menu.dart'; /// status of location bar enum LocationStatus { @@ -124,32 +127,47 @@ class _FileManagerPageState extends State } Widget menu({bool isLocal = false}) { - return PopupMenuButton( - icon: const Icon(Icons.more_vert), - splashRadius: 20, - itemBuilder: (context) { - return [ - PopupMenuItem( - child: Row( - children: [ - Icon( - model.getCurrentShowHidden(isLocal) - ? Icons.check_box_outlined - : Icons.check_box_outline_blank, - color: Colors.black), - SizedBox(width: 5), - Text(translate("Show Hidden Files")) - ], - ), - value: "hidden", - ) - ]; + var menuPos = RelativeRect.fill; + + final items = [ + MenuEntrySwitch( + switchType: SwitchType.scheckbox, + text: translate("Show Hidden Files"), + getter: () async { + return model.getCurrentShowHidden(isLocal); }, - onSelected: (v) { - if (v == "hidden") { - model.toggleShowHidden(local: isLocal); - } - }); + setter: (bool v) async { + model.toggleShowHidden(local: isLocal); + }, + padding: kDesktopMenuPadding, + dismissOnClicked: true, + ), + ]; + + return Listener( + onPointerDown: (e) { + final x = e.position.dx; + final y = e.position.dy; + menuPos = RelativeRect.fromLTRB(x, y, x, y); + }, + child: IconButton( + icon: const Icon(Icons.more_vert), + splashRadius: 20, + onPressed: () => mod_menu.showMenu( + context: context, + position: menuPos, + items: items + .map((e) => e.build( + context, + MenuConfig( + commonColor: CustomPopupMenuTheme.commonColor, + height: CustomPopupMenuTheme.height, + dividerHeight: CustomPopupMenuTheme.dividerHeight))) + .expand((i) => i) + .toList(), + elevation: 8, + ), + )); } Widget body({bool isLocal = false}) { @@ -252,9 +270,8 @@ class _FileManagerPageState extends State getSelectedItem(isLocal).contains(entry), cells: [ DataCell( - ConstrainedBox( - constraints: - BoxConstraints(maxWidth: 180), + Container( + width: 180, child: Tooltip( message: entry.name, child: Row(children: [ @@ -724,9 +741,12 @@ class _FileManagerPageState extends State breadCrumbScrollToEnd(bool isLocal) { Future.delayed(Duration(milliseconds: 200), () { final breadCrumbScroller = getBreadCrumbScrollController(isLocal); - breadCrumbScroller.animateTo(breadCrumbScroller.position.maxScrollExtent, - duration: Duration(milliseconds: 200), - curve: Curves.fastLinearToSlowEaseIn); + if (breadCrumbScroller.hasClients) { + breadCrumbScroller.animateTo( + breadCrumbScroller.position.maxScrollExtent, + duration: Duration(milliseconds: 200), + curve: Curves.fastLinearToSlowEaseIn); + } }); } diff --git a/flutter/lib/desktop/widgets/popup_menu.dart b/flutter/lib/desktop/widgets/popup_menu.dart index 71d1ec417..5f06aebfe 100644 --- a/flutter/lib/desktop/widgets/popup_menu.dart +++ b/flutter/lib/desktop/widgets/popup_menu.dart @@ -3,6 +3,7 @@ import 'dart:core'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import '../../common.dart'; import './material_mod_popup_menu.dart' as mod_menu; // https://stackoverflow.com/questions/68318314/flutter-popup-menu-inside-popup-menu @@ -637,3 +638,10 @@ class MenuEntryButton extends MenuEntryBase { ]; } } + +class CustomPopupMenuTheme { + static const Color commonColor = MyTheme.accent; + // kMinInteractiveDimension + static const double height = 20.0; + static const double dividerHeight = 3.0; +}