opt vote panel

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-07-30 19:20:56 +08:00
parent 83e5095cc3
commit c4e87925cf

View File

@@ -44,37 +44,9 @@ class _VotePanelState extends State<VotePanel> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
return Column( final usePortrait =
mainAxisSize: MainAxisSize.min, context.orientation == Orientation.portrait || context.isTablet;
crossAxisAlignment: CrossAxisAlignment.start, final right = [
children: [
if (_voteInfo.title != null)
Text(_voteInfo.title!, style: theme.textTheme.titleMedium),
if (_voteInfo.desc != null)
Text(_voteInfo.desc!, style: theme.textTheme.titleSmall),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Wrap(
spacing: 10,
runSpacing: 5,
children: [
Text(
'${DateUtil.format(_voteInfo.endTime, format: DateUtil.longFormatDs)}',
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: NumUtil.numFormat(_voteInfo.joinNum),
style: TextStyle(color: theme.colorScheme.primary),
),
const TextSpan(text: '人参与'),
],
),
),
],
),
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -88,10 +60,18 @@ class _VotePanelState extends State<VotePanel> {
if (_enabled) Obx(() => Text('${groupValue.length} / $_maxCnt')), if (_enabled) Obx(() => Text('${groupValue.length} / $_maxCnt')),
], ],
), ),
Flexible(fit: FlexFit.loose, child: _buildContext()), Flexible(
if (_enabled) child: ListView.builder(
key: const PageStorageKey('vote_opions'),
shrinkWrap: true,
itemCount: _voteInfo.options.length,
itemBuilder: (context, index) => _buildOptions(index),
),
),
if (_enabled) ...[
_checkBoxs,
Padding( Padding(
padding: const EdgeInsets.only(top: 16), padding: const EdgeInsets.only(top: 8),
child: Obx( child: Obx(
() => OutlinedButton( () => OutlinedButton(
onPressed: groupValue.isNotEmpty onPressed: groupValue.isNotEmpty
@@ -119,10 +99,68 @@ class _VotePanelState extends State<VotePanel> {
), ),
), ),
], ],
];
Widget child = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_voteInfo.title != null)
Text(_voteInfo.title!, style: theme.textTheme.titleMedium),
if (_voteInfo.desc != null)
Text(
_voteInfo.desc!,
style: theme.textTheme.titleSmall!.copyWith(
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.8),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Wrap(
spacing: 10,
runSpacing: 5,
children: [
Text(
'${DateUtil.format(_voteInfo.endTime, format: DateUtil.longFormatDs)}',
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: NumUtil.numFormat(_voteInfo.joinNum),
style: TextStyle(color: theme.colorScheme.primary),
),
const TextSpan(text: '人参与'),
],
),
),
],
),
),
if (usePortrait) ...right,
],
);
if (!usePortrait) {
child = Row(
spacing: 12,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: child),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: right,
),
),
],
); );
} }
return child;
}
List<Widget> get _checkBoxs => [ Widget get _checkBoxs => Row(
spacing: 16,
children: [
CheckBoxText( CheckBoxText(
text: '显示比例', text: '显示比例',
selected: _showPercentage, selected: _showPercentage,
@@ -139,7 +177,8 @@ class _VotePanelState extends State<VotePanel> {
anonymity = val; anonymity = val;
}, },
), ),
]; ],
);
Widget _buildOptions(int index) { Widget _buildOptions(int index) {
return Padding( return Padding(
@@ -178,19 +217,6 @@ class _VotePanelState extends State<VotePanel> {
} }
} }
Widget _buildContext() {
return CustomScrollView(
shrinkWrap: true,
slivers: [
SliverList.builder(
itemCount: _voteInfo.options.length,
itemBuilder: (context, index) => _buildOptions(index),
),
if (_enabled) SliverList.list(children: _checkBoxs),
],
);
}
static List<double> _cnt2Percentage(List<Option> options) { static List<double> _cnt2Percentage(List<Option> options) {
final total = options.fold(0, (sum, opt) => sum + opt.cnt); final total = options.fold(0, (sum, opt) => sum + opt.cnt);
return total == 0 return total == 0
@@ -288,9 +314,11 @@ Future showVoteDialog(
if (voteInfo.isSuccess) { if (voteInfo.isSuccess) {
showDialog( showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => Dialog(
content: SizedBox( child: ConstrainedBox(
width: 160, constraints: const BoxConstraints(maxWidth: 625),
child: Padding(
padding: const EdgeInsets.all(24),
child: VotePanel( child: VotePanel(
voteInfo: voteInfo.data, voteInfo: voteInfo.data,
callback: (votes, anonymity) => DynamicsHttp.doVote( callback: (votes, anonymity) => DynamicsHttp.doVote(
@@ -302,6 +330,7 @@ Future showVoteDialog(
), ),
), ),
), ),
),
); );
} else { } else {
voteInfo.toast(); voteInfo.toast();