dynamic width based on translated strings #3625
This commit is contained in:
parent
6d149f6ccb
commit
050e107cb6
@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:math';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:bot_toast/bot_toast.dart';
|
import 'package:bot_toast/bot_toast.dart';
|
||||||
@ -453,6 +454,13 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
|
|||||||
color: Theme.of(context).colorScheme.background,
|
color: Theme.of(context).colorScheme.background,
|
||||||
borderRadius: BorderRadius.circular(5),
|
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(
|
return Container(
|
||||||
padding: EdgeInsets.all(4.0),
|
padding: EdgeInsets.all(4.0),
|
||||||
decoration: deco,
|
decoration: deco,
|
||||||
@ -471,12 +479,13 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
|
|||||||
Icons.sort,
|
Icons.sort,
|
||||||
size: 18,
|
size: 18,
|
||||||
),
|
),
|
||||||
|
isExpanded: true,
|
||||||
dropdownStyleData: DropdownStyleData(
|
dropdownStyleData: DropdownStyleData(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).cardColor,
|
color: Theme.of(context).cardColor,
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
width: 160,
|
width: max_width,
|
||||||
),
|
),
|
||||||
items: [
|
items: [
|
||||||
DropdownMenuItem<String>(
|
DropdownMenuItem<String>(
|
||||||
@ -487,7 +496,7 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
|
|||||||
),
|
),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
),
|
),
|
||||||
...PeerSortType.values
|
...translated_text
|
||||||
.map<DropdownMenuItem<String>>(
|
.map<DropdownMenuItem<String>>(
|
||||||
(String value) => DropdownMenuItem<String>(
|
(String value) => DropdownMenuItem<String>(
|
||||||
value: value,
|
value: value,
|
||||||
@ -500,7 +509,7 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
|
|||||||
size: 18,
|
size: 18,
|
||||||
).paddingOnly(right: 12),
|
).paddingOnly(right: 12),
|
||||||
Text(
|
Text(
|
||||||
translate(value),
|
value,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user