Merge pull request #3631 from NicKoehler/sort-fix

Width based on translated strings #3625
This commit is contained in:
RustDesk 2023-03-13 16:13:59 +08:00 committed by GitHub
commit e6784bd9fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
import 'dart:math';
import 'dart:ui' as ui;
import 'package:bot_toast/bot_toast.dart';
@ -453,6 +454,13 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
color: Theme.of(context).colorScheme.background,
borderRadius: BorderRadius.circular(5),
);
final translated_text =
PeerSortType.values.map((e) => translate(e)).toList();
final double max_width =
50 + translated_text.map((e) => e.length).reduce(max) * 10;
return Container(
padding: EdgeInsets.all(4.0),
decoration: deco,
@ -471,12 +479,13 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
Icons.sort,
size: 18,
),
isExpanded: true,
dropdownStyleData: DropdownStyleData(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(10),
),
width: 160,
width: max_width,
),
items: [
DropdownMenuItem<String>(
@ -487,7 +496,7 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
),
enabled: false,
),
...PeerSortType.values
...translated_text
.map<DropdownMenuItem<String>>(
(String value) => DropdownMenuItem<String>(
value: value,
@ -500,7 +509,7 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
size: 18,
).paddingOnly(right: 12),
Text(
translate(value),
value,
overflow: TextOverflow.ellipsis,
),
],