fix sort by menu overflow

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-06-10 06:56:45 +08:00
parent 501323ff6a
commit 583c83ac9b

View File

@ -450,75 +450,43 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final deco = BoxDecoration( List<PopupMenuEntry> items = List.empty(growable: true);
color: Theme.of(context).colorScheme.background, items.add(PopupMenuItem(
borderRadius: BorderRadius.circular(5), enabled: false,
); child: Text(
translate("Sort by"),
final translated_text = { style: TextStyle(fontWeight: FontWeight.bold),
for (var e in PeerSortType.values) e: translate(e) )));
}; for (var e in PeerSortType.values) {
items.add(PopupMenuItem(
final double max_width = child: Obx(() => getRadio(Text(translate(e)), e, peerSort.value,
50 + translated_text.values.map((e) => e.length).reduce(max) * 10; (String? v) async {
return Container(
padding: EdgeInsets.all(4.0),
decoration: deco,
child: DropdownButtonHideUnderline(
child: DropdownButton2<String>(
onChanged: (v) async {
if (v != null) { if (v != null) {
setState(() => peerSort.value = v); peerSort.value = v;
await bind.setLocalFlutterConfig( await bind.setLocalFlutterConfig(
k: "peer-sorting", k: "peer-sorting",
v: peerSort.value, v: peerSort.value,
); );
} }
}, }))));
customButton: Icon( }
return InkWell(
child: Icon(
Icons.sort, Icons.sort,
size: 18, size: 18,
), ),
isExpanded: true, onTapDown: (details) {
dropdownStyleData: DropdownStyleData( final x = details.globalPosition.dx;
decoration: BoxDecoration( final y = details.globalPosition.dy;
color: Theme.of(context).cardColor, final menuPos = RelativeRect.fromLTRB(x, y, x, y);
borderRadius: BorderRadius.circular(10), showMenu(
), context: context,
width: max_width, position: menuPos,
), items: items,
items: [ elevation: 8,
DropdownMenuItem<String>( );
alignment: Alignment.center, },
child: Text(
translate("Sort by"),
style: TextStyle(fontWeight: FontWeight.bold),
),
enabled: false,
),
...translated_text.entries
.map<DropdownMenuItem<String>>(
(MapEntry entry) => DropdownMenuItem<String>(
value: entry.key,
child: Row(
children: [
Icon(
entry.key == peerSort.value
? Icons.radio_button_checked_rounded
: Icons.radio_button_off_rounded,
size: 18,
).paddingOnly(right: 12),
Text(
entry.value,
overflow: TextOverflow.ellipsis,
),
],
),
),
)
.toList(),
]),
),
); );
} }
} }