Migrate Radio groupValue/onChanged to RadioGroup widget

This commit is contained in:
Doug Borg
2026-02-02 00:55:46 -07:00
parent 3570104800
commit e4b36719d7
2 changed files with 73 additions and 71 deletions

View File

@@ -25,6 +25,7 @@ class _LanguageSectionState extends State<LanguageSection> {
Future<void> _loadSelectedLanguage() async {
final prefs = await SharedPreferences.getInstance();
if (!mounted) return;
setState(() {
_selectedLanguage = prefs.getString('language_code');
});
@@ -38,6 +39,7 @@ class _LanguageSectionState extends State<LanguageSection> {
names[langCode] = await locService.getLanguageDisplayName(langCode);
}
if (!mounted) return;
setState(() {
_languageNames = names;
});
@@ -64,30 +66,32 @@ class _LanguageSectionState extends State<LanguageSection> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Language section
RadioGroup<String?>(
groupValue: _selectedLanguage,
onChanged: _setLanguage,
child: Column(
children: [
// System Default option
RadioListTile<String?>(
title: Text(locService.t('settings.systemDefault')),
value: null,
groupValue: _selectedLanguage,
onChanged: _setLanguage,
),
// English always appears second (if available)
if (locService.availableLanguages.contains('en'))
RadioListTile<String>(
RadioListTile<String?>(
title: Text(_languageNames['en'] ?? 'English'),
value: 'en',
groupValue: _selectedLanguage,
onChanged: _setLanguage,
),
// Other language options (excluding English since it's already shown)
...locService.availableLanguages
.where((langCode) => langCode != 'en')
.map((langCode) =>
RadioListTile<String>(
RadioListTile<String?>(
title: Text(_languageNames[langCode] ?? langCode.toUpperCase()),
value: langCode,
groupValue: _selectedLanguage,
onChanged: _setLanguage,
),
),
],
),
),
@@ -105,33 +109,33 @@ class _LanguageSectionState extends State<LanguageSection> {
Text(
locService.t('settings.distanceUnitSubtitle'),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).textTheme.bodySmall?.color?.withOpacity(0.7),
color: Theme.of(context).textTheme.bodySmall?.color?.withValues(alpha: 0.7),
),
),
const SizedBox(height: 8),
// Metric option
RadioListTile<DistanceUnit>(
title: Text(locService.t('units.metricDescription')),
value: DistanceUnit.metric,
RadioGroup<DistanceUnit>(
groupValue: appState.distanceUnit,
onChanged: (unit) {
if (unit != null) {
appState.setDistanceUnit(unit);
}
},
child: Column(
children: [
// Metric option
RadioListTile<DistanceUnit>(
title: Text(locService.t('units.metricDescription')),
value: DistanceUnit.metric,
),
// Imperial option
RadioListTile<DistanceUnit>(
title: Text(locService.t('units.imperialDescription')),
value: DistanceUnit.imperial,
groupValue: appState.distanceUnit,
onChanged: (unit) {
if (unit != null) {
appState.setDistanceUnit(unit);
}
},
),
],
),
),
],
),

View File

@@ -248,6 +248,9 @@ class _RefineTagsSheetState extends State<RefineTagsSheet> {
)
else ...[
Card(
child: RadioGroup<OperatorProfile?>(
groupValue: _selectedOperatorProfile,
onChanged: (value) => setState(() => _selectedOperatorProfile = value),
child: Column(
children: [
// Show existing operator profile first if it exists
@@ -256,8 +259,6 @@ class _RefineTagsSheetState extends State<RefineTagsSheet> {
title: Text(locService.t('refineTagsSheet.existingOperator')),
subtitle: Text('${widget.selectedOperatorProfile!.tags.length} ${locService.t('refineTagsSheet.existingOperatorTags')}'),
value: widget.selectedOperatorProfile,
groupValue: _selectedOperatorProfile,
onChanged: (value) => setState(() => _selectedOperatorProfile = value),
),
const Divider(height: 1),
],
@@ -265,19 +266,16 @@ class _RefineTagsSheetState extends State<RefineTagsSheet> {
title: Text(locService.t('refineTagsSheet.none')),
subtitle: Text(locService.t('refineTagsSheet.noAdditionalOperatorTags')),
value: null,
groupValue: _selectedOperatorProfile,
onChanged: (value) => setState(() => _selectedOperatorProfile = value),
),
...operatorProfiles.map((profile) => RadioListTile<OperatorProfile?>(
title: Text(profile.name),
subtitle: Text('${profile.tags.length} ${locService.t('refineTagsSheet.additionalTags')}'),
value: profile,
groupValue: _selectedOperatorProfile,
onChanged: (value) => setState(() => _selectedOperatorProfile = value),
)),
],
),
),
),
const SizedBox(height: 16),
if (_selectedOperatorProfile != null) ...[
Text(