use shared AddressBookTag widget & hide _editTagAction when tags is empty
This commit is contained in:
parent
a13c4c5907
commit
6a92212216
@ -153,9 +153,10 @@ class _AddressBookState extends State<AddressBook> {
|
|||||||
child: Obx(
|
child: Obx(
|
||||||
() => Wrap(
|
() => Wrap(
|
||||||
children: gFFI.abModel.tags
|
children: gFFI.abModel.tags
|
||||||
.map((e) => buildTag(e, gFFI.abModel.selectedTags,
|
.map((e) => AddressBookTag(
|
||||||
|
name: e,
|
||||||
|
tags: gFFI.abModel.selectedTags,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
//
|
|
||||||
if (gFFI.abModel.selectedTags.contains(e)) {
|
if (gFFI.abModel.selectedTags.contains(e)) {
|
||||||
gFFI.abModel.selectedTags.remove(e);
|
gFFI.abModel.selectedTags.remove(e);
|
||||||
} else {
|
} else {
|
||||||
@ -183,41 +184,6 @@ class _AddressBookState extends State<AddressBook> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildTag(String tagName, RxList<dynamic> rxTags, {Function()? onTap}) {
|
|
||||||
return ContextMenuArea(
|
|
||||||
width: 100,
|
|
||||||
builder: (context) => [
|
|
||||||
ListTile(
|
|
||||||
title: Text(translate("Delete")),
|
|
||||||
onTap: () {
|
|
||||||
gFFI.abModel.deleteTag(tagName);
|
|
||||||
gFFI.abModel.pushAb();
|
|
||||||
Future.delayed(Duration.zero, () => Get.back());
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: Obx(
|
|
||||||
() => Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: rxTags.contains(tagName) ? Colors.blue : null,
|
|
||||||
border: Border.all(color: MyTheme.darkGray),
|
|
||||||
borderRadius: BorderRadius.circular(6)),
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 8.0),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
|
|
||||||
child: Text(
|
|
||||||
tagName,
|
|
||||||
style: TextStyle(
|
|
||||||
color:
|
|
||||||
rxTags.contains(tagName) ? Colors.white : null), // TODO
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// tag operation
|
/// tag operation
|
||||||
void handleAbOp(String value) {
|
void handleAbOp(String value) {
|
||||||
if (value == 'add-id') {
|
if (value == 'add-id') {
|
||||||
@ -366,54 +332,55 @@ class _AddressBookState extends State<AddressBook> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void abEditTag(String id) {
|
|
||||||
var isInProgress = false;
|
|
||||||
|
|
||||||
final tags = List.of(gFFI.abModel.tags);
|
|
||||||
var selectedTag = gFFI.abModel.getPeerTags(id).obs;
|
|
||||||
|
|
||||||
gFFI.dialogManager.show((setState, close) {
|
|
||||||
submit() async {
|
|
||||||
setState(() {
|
|
||||||
isInProgress = true;
|
|
||||||
});
|
|
||||||
gFFI.abModel.changeTagForPeer(id, selectedTag);
|
|
||||||
await gFFI.abModel.pushAb();
|
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return CustomAlertDialog(
|
class AddressBookTag extends StatelessWidget {
|
||||||
title: Text(translate("Edit Tag")),
|
final String name;
|
||||||
content: Column(
|
final RxList<dynamic> tags;
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
final Function()? onTap;
|
||||||
children: [
|
final bool useContextMenuArea;
|
||||||
Container(
|
|
||||||
padding:
|
const AddressBookTag(
|
||||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
{Key? key,
|
||||||
child: Wrap(
|
required this.name,
|
||||||
children: tags
|
required this.tags,
|
||||||
.map((e) => buildTag(e, selectedTag, onTap: () {
|
this.onTap,
|
||||||
if (selectedTag.contains(e)) {
|
this.useContextMenuArea = true})
|
||||||
selectedTag.remove(e);
|
: super(key: key);
|
||||||
} else {
|
|
||||||
selectedTag.add(e);
|
@override
|
||||||
}
|
Widget build(BuildContext context) {
|
||||||
}))
|
final body = GestureDetector(
|
||||||
.toList(growable: false),
|
onTap: onTap,
|
||||||
|
child: Obx(
|
||||||
|
() => Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: tags.contains(name) ? Colors.blue : null,
|
||||||
|
border: Border.all(color: MyTheme.darkGray),
|
||||||
|
borderRadius: BorderRadius.circular(6)),
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 8.0),
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
|
||||||
|
child: Text(name,
|
||||||
|
style:
|
||||||
|
TextStyle(color: tags.contains(name) ? Colors.white : null)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Offstage(
|
|
||||||
offstage: !isInProgress, child: const LinearProgressIndicator())
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(onPressed: close, child: Text(translate("Cancel"))),
|
|
||||||
TextButton(onPressed: submit, child: Text(translate("OK"))),
|
|
||||||
],
|
|
||||||
onSubmit: submit,
|
|
||||||
onCancel: close,
|
|
||||||
);
|
);
|
||||||
});
|
return useContextMenuArea
|
||||||
|
? ContextMenuArea(
|
||||||
|
width: 100,
|
||||||
|
builder: (context) => [
|
||||||
|
ListTile(
|
||||||
|
title: Text(translate("Delete")),
|
||||||
|
onTap: () {
|
||||||
|
gFFI.abModel.deleteTag(name);
|
||||||
|
gFFI.abModel.pushAb();
|
||||||
|
Future.delayed(Duration.zero, () => Get.back());
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
child: body,
|
||||||
|
)
|
||||||
|
: body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:contextmenu/contextmenu.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_hbb/common/widgets/address_book.dart';
|
||||||
import 'package:flutter_hbb/consts.dart';
|
import 'package:flutter_hbb/consts.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
@ -774,7 +774,9 @@ class AddressBookPeerCard extends BasePeerCard {
|
|||||||
if (await bind.mainPeerHasPassword(id: peer.id)) {
|
if (await bind.mainPeerHasPassword(id: peer.id)) {
|
||||||
menuItems.add(_unrememberPasswordAction(peer.id));
|
menuItems.add(_unrememberPasswordAction(peer.id));
|
||||||
}
|
}
|
||||||
|
if (gFFI.abModel.tags.isNotEmpty) {
|
||||||
menuItems.add(_editTagAction(peer.id));
|
menuItems.add(_editTagAction(peer.id));
|
||||||
|
}
|
||||||
return menuItems;
|
return menuItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,17 +838,20 @@ class AddressBookPeerCard extends BasePeerCard {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
children: tags
|
children: tags
|
||||||
.map((e) => _buildTag(e, selectedTag, onTap: () {
|
.map((e) => AddressBookTag(
|
||||||
|
name: e,
|
||||||
|
tags: selectedTag,
|
||||||
|
onTap: () {
|
||||||
if (selectedTag.contains(e)) {
|
if (selectedTag.contains(e)) {
|
||||||
selectedTag.remove(e);
|
selectedTag.remove(e);
|
||||||
} else {
|
} else {
|
||||||
selectedTag.add(e);
|
selectedTag.add(e);
|
||||||
}
|
}
|
||||||
}))
|
},
|
||||||
|
useContextMenuArea: false))
|
||||||
.toList(growable: false),
|
.toList(growable: false),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -863,41 +868,6 @@ class AddressBookPeerCard extends BasePeerCard {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTag(String tagName, RxList<dynamic> rxTags,
|
|
||||||
{Function()? onTap}) {
|
|
||||||
return ContextMenuArea(
|
|
||||||
width: 100,
|
|
||||||
builder: (context) => [
|
|
||||||
ListTile(
|
|
||||||
title: Text(translate("Delete")),
|
|
||||||
onTap: () {
|
|
||||||
gFFI.abModel.deleteTag(tagName);
|
|
||||||
gFFI.abModel.pushAb();
|
|
||||||
Future.delayed(Duration.zero, () => Get.back());
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: Obx(
|
|
||||||
() => Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: rxTags.contains(tagName) ? Colors.blue : null,
|
|
||||||
border: Border.all(color: MyTheme.darkGray),
|
|
||||||
borderRadius: BorderRadius.circular(10)),
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 8.0),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
|
|
||||||
child: Text(
|
|
||||||
tagName,
|
|
||||||
style: TextStyle(
|
|
||||||
color: rxTags.contains(tagName) ? Colors.white : null),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _rdpDialog(String id) async {
|
void _rdpDialog(String id) async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user