sort address book name dropdown (#8127)

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2024-05-23 17:44:48 +08:00 committed by GitHub
parent b8d9c4c378
commit 7da09f6296
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 21 deletions

View File

@ -190,6 +190,40 @@ class _AddressBookState extends State<AddressBook> {
if (!names.contains(gFFI.abModel.currentName.value)) {
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 isOptFixed = isOptionFixed(kOptionCurrentAbName);
@ -208,26 +242,8 @@ class _AddressBookState extends State<AddressBook> {
color: Theme.of(context).dividerColor.withOpacity(0.1),
),
buttonStyleData: ButtonStyleData(height: 48),
menuItemStyleData: MenuItemStyleData(height: 36),
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(),
menuItemStyleData: menuItemStyleData,
items: items,
isExpanded: true,
dropdownSearchData: DropdownSearchData(
searchController: textEditingController,

View File

@ -510,7 +510,8 @@ class AbModel {
}
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;
_timerCounter = 0;
}
@ -648,6 +649,10 @@ class AbModel {
return addressbooks.keys.toList();
}
String personalAddressBookName() {
return _personalAddressBookName;
}
Future<void> setCurrentName(String name) async {
final oldName = _currentName.value;
if (addressbooks.containsKey(name)) {