opt: address book tag action menu desktop style

This commit is contained in:
csf 2022-10-08 19:52:02 +09:00
parent 14d390e23f
commit dc8ddc4364
2 changed files with 53 additions and 33 deletions

View File

@ -1,4 +1,3 @@
import 'package:contextmenu/contextmenu.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/widgets/peer_card.dart'; import 'package:flutter_hbb/common/widgets/peer_card.dart';
import 'package:flutter_hbb/common/widgets/peers_view.dart'; import 'package:flutter_hbb/common/widgets/peers_view.dart';
@ -178,18 +177,6 @@ class _AddressBookState extends State<AddressBook> {
} }
void _showMenu(RelativeRect pos) { void _showMenu(RelativeRect pos) {
MenuEntryButton<String> getEntry(String title, VoidCallback proc) {
return MenuEntryButton<String>(
childBuilder: (TextStyle? style) => Text(
title,
style: style,
),
proc: proc,
padding: kDesktopMenuPadding,
dismissOnClicked: true,
);
}
final items = [ final items = [
getEntry(translate("Add ID"), abAddId), getEntry(translate("Add ID"), abAddId),
getEntry(translate("Add Tag"), abAddTag), getEntry(translate("Add Tag"), abAddTag),
@ -355,20 +342,32 @@ class AddressBookTag extends StatelessWidget {
final String name; final String name;
final RxList<dynamic> tags; final RxList<dynamic> tags;
final Function()? onTap; final Function()? onTap;
final bool useContextMenuArea; final bool showActionMenu;
const AddressBookTag( const AddressBookTag(
{Key? key, {Key? key,
required this.name, required this.name,
required this.tags, required this.tags,
this.onTap, this.onTap,
this.useContextMenuArea = true}) this.showActionMenu = true})
: super(key: key); : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final body = GestureDetector( var pos = RelativeRect.fill;
void setPosition(TapDownDetails e) {
final x = e.globalPosition.dx;
final y = e.globalPosition.dy;
pos = RelativeRect.fromLTRB(x, y, x, y);
}
return GestureDetector(
onTap: onTap, onTap: onTap,
onTapDown: showActionMenu ? setPosition : null,
onSecondaryTapDown: showActionMenu ? setPosition : null,
onSecondaryTap: showActionMenu ? () => _showMenu(context, pos) : null,
onLongPress: showActionMenu ? () => _showMenu(context, pos) : null,
child: Obx( child: Obx(
() => Container( () => Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -383,21 +382,42 @@ class AddressBookTag extends StatelessWidget {
), ),
), ),
); );
return useContextMenuArea }
? ContextMenuArea(
width: 100, void _showMenu(BuildContext context, RelativeRect pos) {
builder: (context) => [ final items = [
ListTile( getEntry(translate("Delete"), () {
title: Text(translate("Delete")), gFFI.abModel.deleteTag(name);
onTap: () { gFFI.abModel.pushAb();
gFFI.abModel.deleteTag(name); Future.delayed(Duration.zero, () => Get.back());
gFFI.abModel.pushAb(); }),
Future.delayed(Duration.zero, () => Get.back()); ];
},
) mod_menu.showMenu(
], context: context,
child: body, position: pos,
) items: items
: body; .map((e) => e.build(
context,
MenuConfig(
commonColor: CustomPopupMenuTheme.commonColor,
height: CustomPopupMenuTheme.height,
dividerHeight: CustomPopupMenuTheme.dividerHeight)))
.expand((i) => i)
.toList(),
elevation: 8,
);
} }
} }
MenuEntryButton<String> getEntry(String title, VoidCallback proc) {
return MenuEntryButton<String>(
childBuilder: (TextStyle? style) => Text(
title,
style: style,
),
proc: proc,
padding: kDesktopMenuPadding,
dismissOnClicked: true,
);
}

View File

@ -830,7 +830,7 @@ class AddressBookPeerCard extends BasePeerCard {
selectedTag.add(e); selectedTag.add(e);
} }
}, },
useContextMenuArea: false)) showActionMenu: false))
.toList(growable: false), .toList(growable: false),
), ),
), ),