mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-20 09:06:36 +08:00
tweaks (#1187)
* opt: marquee * fix: bangumi seek * opt: post panel * opt: remove deprecated code * opt: singleton dynController * fix: music scheme * feat: MemberVideo jump keep position * tweak
This commit is contained in:
committed by
GitHub
parent
e8a674ca2a
commit
172389b12b
@@ -1,43 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class RadioWidget<T> extends StatelessWidget {
|
||||
class RadioWidget<T> extends StatefulWidget {
|
||||
final T value;
|
||||
final T? groupValue;
|
||||
final ValueChanged<T?> onChanged;
|
||||
final String title;
|
||||
final bool tristate;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
final MainAxisSize mainAxisSize;
|
||||
|
||||
const RadioWidget({
|
||||
super.key,
|
||||
required this.value,
|
||||
this.groupValue,
|
||||
required this.onChanged,
|
||||
required this.title,
|
||||
this.tristate = false,
|
||||
this.padding,
|
||||
this.mainAxisSize = MainAxisSize.min,
|
||||
});
|
||||
|
||||
Widget _child() => Row(
|
||||
children: [
|
||||
Radio<T>(
|
||||
value: value,
|
||||
groupValue: groupValue,
|
||||
onChanged: onChanged,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
Text(title),
|
||||
],
|
||||
);
|
||||
@override
|
||||
State<RadioWidget<T>> createState() => RadioWidgetState<T>();
|
||||
}
|
||||
|
||||
class RadioWidgetState<T> extends State<RadioWidget<T>> with RadioClient<T> {
|
||||
late final _RadioRegistry<T> _radioRegistry = _RadioRegistry<T>(this);
|
||||
|
||||
@override
|
||||
final focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
T get radioValue => widget.value;
|
||||
|
||||
bool get checked => radioValue == registry!.groupValue;
|
||||
|
||||
@override
|
||||
bool get tristate => widget.tristate;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
registry = null;
|
||||
focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
registry = RadioGroup.maybeOf(context);
|
||||
assert(registry != null);
|
||||
}
|
||||
|
||||
void _handleTap() {
|
||||
if (checked) {
|
||||
if (tristate) registry!.onChanged(null);
|
||||
return;
|
||||
}
|
||||
registry!.onChanged(radioValue);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final child = Row(
|
||||
mainAxisSize: widget.mainAxisSize,
|
||||
children: [
|
||||
Focus(
|
||||
parentNode: focusNode,
|
||||
canRequestFocus: false,
|
||||
skipTraversal: true,
|
||||
includeSemantics: true,
|
||||
descendantsAreFocusable: false,
|
||||
descendantsAreTraversable: false,
|
||||
child: Radio<T>(
|
||||
value: radioValue,
|
||||
groupRegistry: _radioRegistry,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
Text(widget.title),
|
||||
],
|
||||
);
|
||||
return InkWell(
|
||||
onTap: () => onChanged(value),
|
||||
child: padding != null
|
||||
? Padding(
|
||||
padding: padding!,
|
||||
child: _child(),
|
||||
)
|
||||
: _child(),
|
||||
onTap: _handleTap,
|
||||
focusNode: focusNode,
|
||||
child: widget.padding == null
|
||||
? child
|
||||
: Padding(padding: widget.padding!, child: child),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -45,16 +90,12 @@ class RadioWidget<T> extends StatelessWidget {
|
||||
class WrapRadioOptionsGroup<T> extends StatelessWidget {
|
||||
final String groupTitle;
|
||||
final Map<T, String> options;
|
||||
final T? selectedValue;
|
||||
final ValueChanged<T?> onChanged;
|
||||
final EdgeInsetsGeometry? itemPadding;
|
||||
|
||||
const WrapRadioOptionsGroup({
|
||||
super.key,
|
||||
required this.groupTitle,
|
||||
required this.options,
|
||||
required this.selectedValue,
|
||||
required this.onChanged,
|
||||
this.itemPadding,
|
||||
});
|
||||
|
||||
@@ -75,14 +116,10 @@ class WrapRadioOptionsGroup<T> extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Wrap(
|
||||
children: options.entries.map((entry) {
|
||||
return IntrinsicWidth(
|
||||
child: RadioWidget<T>(
|
||||
value: entry.key,
|
||||
groupValue: selectedValue,
|
||||
onChanged: onChanged,
|
||||
title: entry.value,
|
||||
padding: itemPadding ?? const EdgeInsets.only(right: 10),
|
||||
),
|
||||
return RadioWidget<T>(
|
||||
value: entry.key,
|
||||
title: entry.value,
|
||||
padding: itemPadding ?? const EdgeInsets.only(right: 10),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
@@ -91,3 +128,27 @@ class WrapRadioOptionsGroup<T> extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A registry to controls internal [Radio] and hides it from [RadioGroup]
|
||||
/// ancestor.
|
||||
///
|
||||
/// [RadioListTile] implements the [RadioClient] directly to register to
|
||||
/// [RadioGroup] ancestor. Therefore, it has to hide the internal [Radio] from
|
||||
/// participate in the [RadioGroup] ancestor.
|
||||
class _RadioRegistry<T> extends RadioGroupRegistry<T> {
|
||||
_RadioRegistry(this.state);
|
||||
|
||||
final RadioWidgetState<T> state;
|
||||
|
||||
@override
|
||||
T? get groupValue => state.registry!.groupValue;
|
||||
|
||||
@override
|
||||
ValueChanged<T?> get onChanged => state.registry!.onChanged;
|
||||
|
||||
@override
|
||||
void registerClient(RadioClient<T> radio) {}
|
||||
|
||||
@override
|
||||
void unregisterClient(RadioClient<T> radio) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user