mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 23:19:02 +08:00
sort address book name dropdown (#8127)
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
b8d9c4c378
commit
7da09f6296
@ -190,6 +190,40 @@ class _AddressBookState extends State<AddressBook> {
|
|||||||
if (!names.contains(gFFI.abModel.currentName.value)) {
|
if (!names.contains(gFFI.abModel.currentName.value)) {
|
||||||
return Offstage();
|
return Offstage();
|
||||||
}
|
}
|
||||||
|
// order: personal, divider, character order
|
||||||
|
// https://pub.dev/packages/dropdown_button2#3-dropdownbutton2-with-items-of-different-heights-like-dividers
|
||||||
|
final personalAddressBookName = gFFI.abModel.personalAddressBookName();
|
||||||
|
bool contains = names.remove(personalAddressBookName);
|
||||||
|
names.sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));
|
||||||
|
if (contains) {
|
||||||
|
names.insert(0, personalAddressBookName);
|
||||||
|
}
|
||||||
|
final items = names
|
||||||
|
.map((e) => DropdownMenuItem(
|
||||||
|
value: e,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Tooltip(
|
||||||
|
waitDuration: Duration(milliseconds: 500),
|
||||||
|
message: gFFI.abModel.translatedName(e),
|
||||||
|
child: Text(
|
||||||
|
gFFI.abModel.translatedName(e),
|
||||||
|
style: TextStyle(fontSize: 14.0),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)))
|
||||||
|
.toList();
|
||||||
|
var menuItemStyleData = MenuItemStyleData(height: 36);
|
||||||
|
if (contains && items.length > 1) {
|
||||||
|
items.insert(1, DropdownMenuItem(enabled: false, child: Divider()));
|
||||||
|
List<double> customHeights = List.filled(items.length, 36);
|
||||||
|
customHeights[1] = 4;
|
||||||
|
menuItemStyleData = MenuItemStyleData(customHeights: customHeights);
|
||||||
|
}
|
||||||
final TextEditingController textEditingController = TextEditingController();
|
final TextEditingController textEditingController = TextEditingController();
|
||||||
|
|
||||||
final isOptFixed = isOptionFixed(kOptionCurrentAbName);
|
final isOptFixed = isOptionFixed(kOptionCurrentAbName);
|
||||||
@ -208,26 +242,8 @@ class _AddressBookState extends State<AddressBook> {
|
|||||||
color: Theme.of(context).dividerColor.withOpacity(0.1),
|
color: Theme.of(context).dividerColor.withOpacity(0.1),
|
||||||
),
|
),
|
||||||
buttonStyleData: ButtonStyleData(height: 48),
|
buttonStyleData: ButtonStyleData(height: 48),
|
||||||
menuItemStyleData: MenuItemStyleData(height: 36),
|
menuItemStyleData: menuItemStyleData,
|
||||||
items: names
|
items: items,
|
||||||
.map((e) => DropdownMenuItem(
|
|
||||||
value: e,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Tooltip(
|
|
||||||
waitDuration: Duration(milliseconds: 500),
|
|
||||||
message: gFFI.abModel.translatedName(e),
|
|
||||||
child: Text(
|
|
||||||
gFFI.abModel.translatedName(e),
|
|
||||||
style: TextStyle(fontSize: 14.0),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)))
|
|
||||||
.toList(),
|
|
||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
dropdownSearchData: DropdownSearchData(
|
dropdownSearchData: DropdownSearchData(
|
||||||
searchController: textEditingController,
|
searchController: textEditingController,
|
||||||
|
@ -510,7 +510,8 @@ class AbModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setShouldAsync(bool v) async {
|
void setShouldAsync(bool v) async {
|
||||||
await bind.mainSetLocalOption(key: syncAbOption, value: v ? 'Y' : defaultOptionNo);
|
await bind.mainSetLocalOption(
|
||||||
|
key: syncAbOption, value: v ? 'Y' : defaultOptionNo);
|
||||||
_syncAllFromRecent = true;
|
_syncAllFromRecent = true;
|
||||||
_timerCounter = 0;
|
_timerCounter = 0;
|
||||||
}
|
}
|
||||||
@ -648,6 +649,10 @@ class AbModel {
|
|||||||
return addressbooks.keys.toList();
|
return addressbooks.keys.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String personalAddressBookName() {
|
||||||
|
return _personalAddressBookName;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> setCurrentName(String name) async {
|
Future<void> setCurrentName(String name) async {
|
||||||
final oldName = _currentName.value;
|
final oldName = _currentName.value;
|
||||||
if (addressbooks.containsKey(name)) {
|
if (addressbooks.containsKey(name)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user