75 lines
2.2 KiB
Dart
75 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:uae_stat/config/theme/app_theme.dart';
|
|
|
|
class ThemeSelectorDialog extends StatefulWidget {
|
|
final AppTheme initialTheme;
|
|
|
|
const ThemeSelectorDialog({super.key, required this.initialTheme});
|
|
|
|
@override
|
|
State<ThemeSelectorDialog> createState() => _ThemeSelectorDialogState();
|
|
}
|
|
|
|
class _ThemeSelectorDialogState extends State<ThemeSelectorDialog> {
|
|
AppTheme? _selectedTheme;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
print("InitailTheme - ${widget.initialTheme}");
|
|
_loadTheme();
|
|
|
|
// _selectedTheme = widget.initialTheme;
|
|
}
|
|
|
|
Future<void> _loadTheme() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storedTheme = prefs.getString('ThemeType') ?? widget.initialTheme;
|
|
print("storedTheme - $storedTheme");
|
|
setState(() {
|
|
_selectedTheme =
|
|
storedTheme == 'system' ? AppTheme.system : widget.initialTheme;
|
|
});
|
|
|
|
print("_selectedTheme - $_selectedTheme");
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: const Text("Choose Theme"),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: AppTheme.values.map((theme) {
|
|
print("THEME_DIAL1- $theme");
|
|
return RadioListTile<AppTheme>(
|
|
title:
|
|
Text(theme.name[0].toUpperCase() + theme.name.substring(1)),
|
|
value: theme,
|
|
groupValue: _selectedTheme,
|
|
onChanged: (value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
print("THEME_DIALval- $value");
|
|
// Store enum as string
|
|
await prefs.setString(
|
|
'ThemeType', value.toString().split('.').last);
|
|
|
|
setState(() => _selectedTheme = value!);
|
|
});
|
|
}).toList(),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(null),
|
|
child: const Text("Cancel"),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.of(context).pop(_selectedTheme),
|
|
child: const Text("OK"),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
} |