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,64 +155,60 @@ 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>(
mainAxisSize: MainAxisSize.min, groupValue: selected,
children: [ onChanged: (v) {
RadioListTile<int>( setState(() {
value: -1, selected = v ?? selected;
groupValue: selected, });
title: Text("Normal".tl), },
onChanged: (v) { child: Column(
setState(() { mainAxisSize: MainAxisSize.min,
selected = v!; children: [
}); RadioListTile<int>(
}, value: -1,
), title: Text("Normal".tl),
ExpansionTile(
title: Text("Archive".tl),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
), ),
collapsedShape: const RoundedRectangleBorder( ExpansionTile(
borderRadius: BorderRadius.zero, title: Text("Archive".tl),
), shape: const RoundedRectangleBorder(
onExpansionChanged: (b) { borderRadius: BorderRadius.zero,
if (!isLoading && b && archives == null) { ),
isLoading = true; collapsedShape: const RoundedRectangleBorder(
comicSource.archiveDownloader! borderRadius: BorderRadius.zero,
.getArchives(comic.id) ),
.then((value) { onExpansionChanged: (b) {
if (value.success) { if (!isLoading && b && archives == null) {
archives = value.data; isLoading = true;
} else { comicSource.archiveDownloader!
App.rootContext .getArchives(comic.id)
.showMessage(message: value.errorMessage!); .then((value) {
} if (value.success) {
setState(() { archives = value.data;
isLoading = false; } else {
App.rootContext
.showMessage(message: value.errorMessage!);
}
setState(() {
isLoading = false;
});
}); });
}); }
} },
}, children: [
children: [ if (archives == null)
if (archives == null) const ListLoadingIndicator().toCenter()
const ListLoadingIndicator().toCenter() else
else for (int i = 0; i < archives!.length; i++)
for (int i = 0; i < archives!.length; i++) RadioListTile<int>(
RadioListTile<int>( value: i,
value: i, title: Text(archives![i].title),
groupValue: selected, subtitle: Text(archives![i].description),
onChanged: (v) { )
setState(() { ],
selected = v!; )
}); ],
}, ),
title: Text(archives![i].title),
subtitle: Text(archives![i].description),
)
],
)
],
), ),
actions: [ actions: [
Button.filled( Button.filled(

View File

@@ -514,51 +514,53 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
), ),
) )
: Column( : RadioGroup<int>(
key: key, groupValue: type,
crossAxisAlignment: CrossAxisAlignment.start, onChanged: (value) {
children: [ setState(() {
const SizedBox(width: 600), type = value ?? type;
...List.generate(importMethods.length, (index) { });
return RadioListTile( },
title: Text(importMethods[index]), child: Column(
value: index, key: key,
groupValue: type, crossAxisAlignment: CrossAxisAlignment.start,
onChanged: (value) { children: [
setState(() { const SizedBox(width: 600),
type = value as int; ...List.generate(importMethods.length, (index) {
}); return RadioListTile<int>(
}, title: Text(importMethods[index]),
); value: index,
}), );
if (type != 4) }),
ListTile( if (type != 4)
title: Text("Add to favorites".tl), ListTile(
trailing: Select( title: Text("Add to favorites".tl),
current: selectedFolder, trailing: Select(
values: folders, current: selectedFolder,
minWidth: 112, values: folders,
onTap: (v) { minWidth: 112,
setState(() { onTap: (v) {
selectedFolder = folders[v]; setState(() {
}); selectedFolder = folders[v];
}, });
), },
).paddingHorizontal(8), ),
if (!App.isIOS && !App.isMacOS && type != 2 && type != 3) ).paddingHorizontal(8),
CheckboxListTile( if (!App.isIOS && !App.isMacOS && type != 2 && type != 3)
enabled: true, CheckboxListTile(
title: Text("Copy to app local path".tl), enabled: true,
value: copyToLocalFolder, title: Text("Copy to app local path".tl),
onChanged: (v) { value: copyToLocalFolder,
setState(() { onChanged: (v) {
copyToLocalFolder = !copyToLocalFolder; setState(() {
}); copyToLocalFolder = !copyToLocalFolder;
}).paddingHorizontal(8), });
const SizedBox(height: 8), }).paddingHorizontal(8),
Text(info).paddingHorizontal(24), const SizedBox(height: 8),
], Text(info).paddingHorizontal(24),
), ],
),
),
actions: [ actions: [
Button.text( Button.text(
child: Row( child: Row(

View File

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

View File

@@ -70,39 +70,29 @@ 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>(
children: [ groupValue: sortType,
RadioListTile<LocalSortType>( onChanged: (v) {
title: Text("Name".tl), setState(() {
value: LocalSortType.name, sortType = v ?? sortType;
groupValue: sortType, });
onChanged: (v) { },
setState(() { child: Column(
sortType = v!; children: [
}); RadioListTile<LocalSortType>(
}, title: Text("Name".tl),
), value: LocalSortType.name,
RadioListTile<LocalSortType>( ),
title: Text("Date".tl), RadioListTile<LocalSortType>(
value: LocalSortType.timeAsc, title: Text("Date".tl),
groupValue: sortType, value: LocalSortType.timeAsc,
onChanged: (v) { ),
setState(() { RadioListTile<LocalSortType>(
sortType = v!; title: Text("Date Desc".tl),
}); value: LocalSortType.timeDesc,
}, ),
), ],
RadioListTile<LocalSortType>( ),
title: Text("Date Desc".tl),
value: LocalSortType.timeDesc,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
),
],
), ),
actions: [ actions: [
FilledButton( FilledButton(

View File

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

View File

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