Refactor radio button implementations to use RadioGroup.

This commit is contained in:
2025-10-13 20:12:47 +08:00
parent ebc106d45b
commit 3426d707fe
7 changed files with 188 additions and 212 deletions

View File

@@ -23,7 +23,7 @@ linter:
rules: rules:
collection_methods_unrelated_type: false collection_methods_unrelated_type: false
use_build_context_synchronously: false use_build_context_synchronously: false
# avoid_print: false # Uncomment to disable the `avoid_print` rule avoid_print: false
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
# Additional information about this file can be found at # Additional information about this file can be found at

View File

@@ -155,18 +155,19 @@ abstract mixin class _ComicPageActions {
builder: (context, setState) { builder: (context, setState) {
return ContentDialog( return ContentDialog(
title: "Download".tl, title: "Download".tl,
content: Column( content: RadioGroup<int>(
groupValue: selected,
onChanged: (v) {
setState(() {
selected = v ?? selected;
});
},
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
RadioListTile<int>( RadioListTile<int>(
value: -1, value: -1,
groupValue: selected,
title: Text("Normal".tl), title: Text("Normal".tl),
onChanged: (v) {
setState(() {
selected = v!;
});
},
), ),
ExpansionTile( ExpansionTile(
title: Text("Archive".tl), title: Text("Archive".tl),
@@ -201,12 +202,6 @@ abstract mixin class _ComicPageActions {
for (int i = 0; i < archives!.length; i++) for (int i = 0; i < archives!.length; i++)
RadioListTile<int>( RadioListTile<int>(
value: i, value: i,
groupValue: selected,
onChanged: (v) {
setState(() {
selected = v!;
});
},
title: Text(archives![i].title), title: Text(archives![i].title),
subtitle: Text(archives![i].description), subtitle: Text(archives![i].description),
) )
@@ -214,6 +209,7 @@ abstract mixin class _ComicPageActions {
) )
], ],
), ),
),
actions: [ actions: [
Button.filled( Button.filled(
isLoading: isGettingLink, isLoading: isGettingLink,

View File

@@ -514,21 +514,22 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
), ),
) )
: Column( : RadioGroup<int>(
groupValue: type,
onChanged: (value) {
setState(() {
type = value ?? type;
});
},
child: Column(
key: key, key: key,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const SizedBox(width: 600), const SizedBox(width: 600),
...List.generate(importMethods.length, (index) { ...List.generate(importMethods.length, (index) {
return RadioListTile( return RadioListTile<int>(
title: Text(importMethods[index]), title: Text(importMethods[index]),
value: index, value: index,
groupValue: type,
onChanged: (value) {
setState(() {
type = value as int;
});
},
); );
}), }),
if (type != 4) if (type != 4)
@@ -559,6 +560,7 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
Text(info).paddingHorizontal(24), Text(info).paddingHorizontal(24),
], ],
), ),
),
actions: [ actions: [
Button.text( Button.text(
child: Row( child: Row(

View File

@@ -404,22 +404,24 @@ class _ImageFavoritesDialogState extends State<_ImageFavoritesDialog> {
children: [ children: [
tabBar, tabBar,
TabViewBody(children: [ TabViewBody(children: [
Column( RadioGroup<ImageFavoriteSortType>(
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v ?? sortType;
});
},
child: Column(
children: ImageFavoriteSortType.values children: ImageFavoriteSortType.values
.map( .map(
(e) => RadioListTile<ImageFavoriteSortType>( (e) => RadioListTile<ImageFavoriteSortType>(
title: Text(e.value.tl), title: Text(e.value.tl),
value: e, value: e,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
), ),
) )
.toList(), .toList(),
), ),
),
Column( Column(
children: [ children: [
ListTile( ListTile(

View File

@@ -70,40 +70,30 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
return StatefulBuilder(builder: (context, setState) { return StatefulBuilder(builder: (context, setState) {
return ContentDialog( return ContentDialog(
title: "Sort".tl, title: "Sort".tl,
content: Column( content: RadioGroup<LocalSortType>(
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v ?? sortType;
});
},
child: Column(
children: [ children: [
RadioListTile<LocalSortType>( RadioListTile<LocalSortType>(
title: Text("Name".tl), title: Text("Name".tl),
value: LocalSortType.name, value: LocalSortType.name,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
), ),
RadioListTile<LocalSortType>( RadioListTile<LocalSortType>(
title: Text("Date".tl), title: Text("Date".tl),
value: LocalSortType.timeAsc, value: LocalSortType.timeAsc,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
), ),
RadioListTile<LocalSortType>( RadioListTile<LocalSortType>(
title: Text("Date Desc".tl), title: Text("Date Desc".tl),
value: LocalSortType.timeDesc, value: LocalSortType.timeDesc,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
), ),
], ],
), ),
),
actions: [ actions: [
FilledButton( FilledButton(
onPressed: () { onPressed: () {

View File

@@ -428,31 +428,27 @@ class _WebdavSettingState extends State<_WebdavSetting> {
), ),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
Row( RadioGroup<bool>(
groupValue: upload,
onChanged: (value) {
setState(() {
upload = value ?? upload;
});
},
child: Row(
children: [ children: [
Text("Operation".tl), Text("Operation".tl),
Radio<bool>( Radio<bool>(
groupValue: upload,
value: true, value: true,
onChanged: (value) {
setState(() {
upload = value!;
});
},
), ),
Text("Upload".tl), Text("Upload".tl),
Radio<bool>( Radio<bool>(
groupValue: upload,
value: false, value: false,
onChanged: (value) {
setState(() {
upload = value!;
});
},
), ),
Text("Download".tl), Text("Download".tl),
], ],
), ),
),
const SizedBox(height: 16), const SizedBox(height: 16),
AnimatedSize( AnimatedSize(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),

View File

@@ -111,46 +111,36 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
return PopUpWidgetScaffold( return PopUpWidgetScaffold(
title: "Proxy".tl, title: "Proxy".tl,
body: SingleChildScrollView( body: SingleChildScrollView(
child: RadioGroup<String>(
groupValue: type,
onChanged: (v) {
setState(() {
type = v ?? type;
});
if (type != 'manual') {
appdata.settings['proxy'] = toProxyStr();
appdata.saveData();
}
},
child: Column( child: Column(
children: [ children: [
RadioListTile<String>( RadioListTile<String>(
title: Text("Direct".tl), title: Text("Direct".tl),
value: 'direct', value: 'direct',
groupValue: type,
onChanged: (v) {
setState(() {
type = v!;
});
appdata.settings['proxy'] = toProxyStr();
appdata.saveData();
},
), ),
RadioListTile<String>( RadioListTile<String>(
title: Text("System".tl), title: Text("System".tl),
value: 'system', value: 'system',
groupValue: type,
onChanged: (v) {
setState(() {
type = v!;
});
appdata.settings['proxy'] = toProxyStr();
appdata.saveData();
},
), ),
RadioListTile( RadioListTile(
title: Text("Manual".tl), title: Text("Manual".tl),
value: 'manual', value: 'manual',
groupValue: type,
onChanged: (v) {
setState(() {
type = v!;
});
},
), ),
if (type == 'manual') buildManualProxy(), if (type == 'manual') buildManualProxy(),
], ],
), ),
), ),
),
); );
} }