fix sort by menu overflow
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
501323ff6a
commit
583c83ac9b
@ -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"),
|
||||||
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
)));
|
||||||
|
for (var e in PeerSortType.values) {
|
||||||
|
items.add(PopupMenuItem(
|
||||||
|
child: Obx(() => getRadio(Text(translate(e)), e, peerSort.value,
|
||||||
|
(String? v) async {
|
||||||
|
if (v != null) {
|
||||||
|
peerSort.value = v;
|
||||||
|
await bind.setLocalFlutterConfig(
|
||||||
|
k: "peer-sorting",
|
||||||
|
v: peerSort.value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}))));
|
||||||
|
}
|
||||||
|
|
||||||
final translated_text = {
|
return InkWell(
|
||||||
for (var e in PeerSortType.values) e: translate(e)
|
child: Icon(
|
||||||
};
|
Icons.sort,
|
||||||
|
size: 18,
|
||||||
final double max_width =
|
|
||||||
50 + translated_text.values.map((e) => e.length).reduce(max) * 10;
|
|
||||||
return Container(
|
|
||||||
padding: EdgeInsets.all(4.0),
|
|
||||||
decoration: deco,
|
|
||||||
child: DropdownButtonHideUnderline(
|
|
||||||
child: DropdownButton2<String>(
|
|
||||||
onChanged: (v) async {
|
|
||||||
if (v != null) {
|
|
||||||
setState(() => peerSort.value = v);
|
|
||||||
await bind.setLocalFlutterConfig(
|
|
||||||
k: "peer-sorting",
|
|
||||||
v: peerSort.value,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
customButton: Icon(
|
|
||||||
Icons.sort,
|
|
||||||
size: 18,
|
|
||||||
),
|
|
||||||
isExpanded: true,
|
|
||||||
dropdownStyleData: DropdownStyleData(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).cardColor,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
width: max_width,
|
|
||||||
),
|
|
||||||
items: [
|
|
||||||
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(),
|
|
||||||
]),
|
|
||||||
),
|
),
|
||||||
|
onTapDown: (details) {
|
||||||
|
final x = details.globalPosition.dx;
|
||||||
|
final y = details.globalPosition.dy;
|
||||||
|
final menuPos = RelativeRect.fromLTRB(x, y, x, y);
|
||||||
|
showMenu(
|
||||||
|
context: context,
|
||||||
|
position: menuPos,
|
||||||
|
items: items,
|
||||||
|
elevation: 8,
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user