mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 16:48:16 +08:00
fix PopupMenuText
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -3,9 +3,9 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart
|
|||||||
|
|
||||||
typedef PopupMenuItemSelected<T> = bool Function(T value);
|
typedef PopupMenuItemSelected<T> = bool Function(T value);
|
||||||
|
|
||||||
class PopupMenuText<T> extends StatefulWidget {
|
class PopupMenuText<T> extends StatelessWidget {
|
||||||
final String title;
|
final String title;
|
||||||
final T initialValue;
|
final T Function() value;
|
||||||
final PopupMenuItemSelected<T> onSelected;
|
final PopupMenuItemSelected<T> onSelected;
|
||||||
final PopupMenuItemBuilder<T> itemBuilder;
|
final PopupMenuItemBuilder<T> itemBuilder;
|
||||||
final String Function(T) getSelectTitle;
|
final String Function(T) getSelectTitle;
|
||||||
@@ -13,50 +13,34 @@ class PopupMenuText<T> extends StatefulWidget {
|
|||||||
const PopupMenuText({
|
const PopupMenuText({
|
||||||
super.key,
|
super.key,
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.initialValue,
|
required this.value,
|
||||||
required this.onSelected,
|
required this.onSelected,
|
||||||
required this.itemBuilder,
|
required this.itemBuilder,
|
||||||
required this.getSelectTitle,
|
required this.getSelectTitle,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
|
||||||
State<PopupMenuText<T>> createState() => _PopupMenuTextState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PopupMenuTextState<T> extends State<PopupMenuText<T>> {
|
|
||||||
late T select = widget.initialValue;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(PopupMenuText<T> oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (oldWidget.initialValue != widget.initialValue) {
|
|
||||||
select = widget.initialValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final select = value();
|
||||||
final secondary = Theme.of(context).colorScheme.secondary;
|
final secondary = Theme.of(context).colorScheme.secondary;
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text('${widget.title}: '),
|
Text('$title: '),
|
||||||
PopupMenuButton<T>(
|
PopupMenuButton<T>(
|
||||||
initialValue: select,
|
initialValue: select,
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
if (value == select) return;
|
if (value == select) return;
|
||||||
if (!widget.onSelected(value)) {
|
if (!onSelected(value)) {
|
||||||
setState(() {
|
(context as Element).markNeedsBuild();
|
||||||
select = value;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
itemBuilder: widget.itemBuilder,
|
itemBuilder: itemBuilder,
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
widget.getSelectTitle(select),
|
getSelectTitle(select),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
height: 1,
|
height: 1,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ class _PostPanelState extends State<PostPanel>
|
|||||||
children: [
|
children: [
|
||||||
PopupMenuText(
|
PopupMenuText(
|
||||||
title: '分类',
|
title: '分类',
|
||||||
initialValue: item.category,
|
value: () => item.category,
|
||||||
onSelected: (e) {
|
onSelected: (e) {
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
if (item.category == SegmentType.exclusive_access ||
|
if (item.category == SegmentType.exclusive_access ||
|
||||||
@@ -406,7 +406,7 @@ class _PostPanelState extends State<PostPanel>
|
|||||||
),
|
),
|
||||||
PopupMenuText(
|
PopupMenuText(
|
||||||
title: '行为类别',
|
title: '行为类别',
|
||||||
initialValue: item.actionType,
|
value: () => item.actionType,
|
||||||
onSelected: (e) {
|
onSelected: (e) {
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
if (item.actionType == ActionType.full) {
|
if (item.actionType == ActionType.full) {
|
||||||
|
|||||||
@@ -2169,7 +2169,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
),
|
),
|
||||||
PopupMenuText(
|
PopupMenuText(
|
||||||
title: '选择画质',
|
title: '选择画质',
|
||||||
initialValue: qa.code,
|
value: () => qa.code,
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
final video = videoDetailController.findVideoByQa(value);
|
final video = videoDetailController.findVideoByQa(value);
|
||||||
url = video.baseUrl;
|
url = video.baseUrl;
|
||||||
@@ -2189,7 +2189,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
),
|
),
|
||||||
PopupMenuText(
|
PopupMenuText(
|
||||||
title: 'webp预设',
|
title: 'webp预设',
|
||||||
initialValue: preset,
|
value: () => preset,
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
preset = value;
|
preset = value;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user