mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
stableee
This commit is contained in:
@@ -74,22 +74,24 @@ final currencyProvider = StateNotifierProvider<CurrencyNotifier, CurrencyInfo>(
|
|||||||
class ThemeModeNotifier extends StateNotifier<ThemeMode> {
|
class ThemeModeNotifier extends StateNotifier<ThemeMode> {
|
||||||
final SharedPreferences _prefs;
|
final SharedPreferences _prefs;
|
||||||
|
|
||||||
ThemeModeNotifier(this._prefs) : super(ThemeMode.dark) {
|
ThemeModeNotifier(this._prefs) : super(ThemeMode.system) {
|
||||||
_load();
|
_load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _load() {
|
void _load() {
|
||||||
state = (_prefs.getBool('dark_mode') ?? true) ? ThemeMode.dark : ThemeMode.light;
|
final saved = _prefs.getString('theme_mode');
|
||||||
|
if (saved == 'dark') {
|
||||||
|
state = ThemeMode.dark;
|
||||||
|
} else if (saved == 'light') {
|
||||||
|
state = ThemeMode.light;
|
||||||
|
} else {
|
||||||
|
state = ThemeMode.system;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> toggle() async {
|
Future<void> setThemeMode(ThemeMode mode) async {
|
||||||
state = state == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
|
state = mode;
|
||||||
await _prefs.setBool('dark_mode', state == ThemeMode.dark);
|
await _prefs.setString('theme_mode', mode.name);
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setThemeMode(bool isDark) async {
|
|
||||||
state = isDark ? ThemeMode.dark : ThemeMode.light;
|
|
||||||
await _prefs.setBool('dark_mode', isDark);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -213,11 +213,9 @@ class _BiometricSectionState extends ConsumerState<_BiometricSection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future _onToggle(bool val) async {
|
Future _onToggle(bool val) async {
|
||||||
if (val) {
|
final ok = await BiometricService.authenticate();
|
||||||
final ok = await BiometricService.authenticate();
|
if (!ok) return;
|
||||||
if (!ok) return;
|
HapticService.light();
|
||||||
HapticService.light();
|
|
||||||
}
|
|
||||||
await BiometricService.setEnabled(val);
|
await BiometricService.setEnabled(val);
|
||||||
if (mounted) setState(() => _enabled = val);
|
if (mounted) setState(() => _enabled = val);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class ThemeSection extends ConsumerWidget {
|
|||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final s = ref.watch(stringsProvider);
|
final s = ref.watch(stringsProvider);
|
||||||
final themeMode = ref.watch(themeProvider);
|
final themeMode = ref.watch(themeProvider);
|
||||||
final isDarkMode = themeMode == ThemeMode.dark;
|
|
||||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
@@ -21,50 +20,133 @@ class ThemeSection extends ConsumerWidget {
|
|||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
border: isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
border: isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Row(
|
||||||
padding: const EdgeInsets.all(10),
|
children: [
|
||||||
decoration: BoxDecoration(
|
Container(
|
||||||
color: AppColors.accent.withOpacity(0.15),
|
padding: const EdgeInsets.all(10),
|
||||||
borderRadius: BorderRadius.circular(12),
|
decoration: BoxDecoration(
|
||||||
),
|
color: AppColors.accent.withOpacity(0.15),
|
||||||
child: Icon(
|
borderRadius: BorderRadius.circular(12),
|
||||||
isDarkMode ? Icons.dark_mode_rounded : Icons.light_mode_rounded,
|
|
||||||
color: AppColors.accent,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
s.darkMode,
|
|
||||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Text(
|
child: Icon(
|
||||||
isDarkMode ? s.enabled : s.disabled,
|
themeMode == ThemeMode.dark
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
? Icons.dark_mode_rounded
|
||||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
: themeMode == ThemeMode.light
|
||||||
),
|
? Icons.light_mode_rounded
|
||||||
|
: Icons.brightness_auto_rounded,
|
||||||
|
color: AppColors.accent,
|
||||||
|
size: 20,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
const SizedBox(width: 12),
|
||||||
|
Text(
|
||||||
|
s.theme,
|
||||||
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Switch(
|
const SizedBox(height: 16),
|
||||||
value: isDarkMode,
|
Row(
|
||||||
onChanged: (value) {
|
children: [
|
||||||
ref.read(themeProvider.notifier).setThemeMode(value);
|
Expanded(
|
||||||
},
|
child: _ThemeOption(
|
||||||
activeThumbColor: AppColors.accent,
|
label: s.themeDark,
|
||||||
|
icon: Icons.dark_mode_rounded,
|
||||||
|
isSelected: themeMode == ThemeMode.dark,
|
||||||
|
onTap: () => ref.read(themeProvider.notifier).setThemeMode(ThemeMode.dark),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: _ThemeOption(
|
||||||
|
label: s.themeSystem,
|
||||||
|
icon: Icons.brightness_auto_rounded,
|
||||||
|
isSelected: themeMode == ThemeMode.system,
|
||||||
|
onTap: () => ref.read(themeProvider.notifier).setThemeMode(ThemeMode.system),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: _ThemeOption(
|
||||||
|
label: s.themeLight,
|
||||||
|
icon: Icons.light_mode_rounded,
|
||||||
|
isSelected: themeMode == ThemeMode.light,
|
||||||
|
onTap: () => ref.read(themeProvider.notifier).setThemeMode(ThemeMode.light),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _ThemeOption extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
final IconData icon;
|
||||||
|
final bool isSelected;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
const _ThemeOption({
|
||||||
|
required this.label,
|
||||||
|
required this.icon,
|
||||||
|
required this.isSelected,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isSelected
|
||||||
|
? AppColors.accent.withOpacity(0.15)
|
||||||
|
: (isDark ? Colors.white.withOpacity(0.05) : Colors.black.withOpacity(0.03)),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(
|
||||||
|
color: isSelected
|
||||||
|
? AppColors.accent
|
||||||
|
: (isDark ? Colors.white.withOpacity(0.1) : Colors.black.withOpacity(0.08)),
|
||||||
|
width: isSelected ? 2 : 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
color: isSelected
|
||||||
|
? AppColors.accent
|
||||||
|
: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
|
||||||
|
size: 22,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||||
|
color: isSelected
|
||||||
|
? AppColors.accent
|
||||||
|
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user