mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -5,7 +5,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../core/constants.dart';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import '../../shared/services/exchange_rate_service.dart';
|
||||
import '../../shared/utils/currency_utils.dart';
|
||||
@@ -48,52 +47,57 @@ const Map<String, CurrencyInfo> currencyMap = {
|
||||
};
|
||||
|
||||
class CurrencyNotifier extends StateNotifier<CurrencyInfo> {
|
||||
CurrencyNotifier() : super(currencyMap['USD']!) {
|
||||
final SharedPreferences _prefs;
|
||||
|
||||
CurrencyNotifier(this._prefs) : super(currencyMap['USD']!) {
|
||||
_load();
|
||||
}
|
||||
|
||||
void _load() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final code = prefs.getString('currency_code') ?? 'USD';
|
||||
void _load() {
|
||||
final code = _prefs.getString('currency_code') ?? 'USD';
|
||||
state = currencyMap[code] ?? currencyMap['USD']!;
|
||||
}
|
||||
|
||||
Future<void> setCurrency(String code) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
state = currencyMap[code] ?? currencyMap['USD']!;
|
||||
await prefs.setString('currency_code', code);
|
||||
await _prefs.setString('currency_code', code);
|
||||
}
|
||||
}
|
||||
|
||||
final currencyProvider = StateNotifierProvider<CurrencyNotifier, CurrencyInfo>(
|
||||
(ref) => CurrencyNotifier(),
|
||||
(ref) {
|
||||
final prefs = ref.watch(sharedPreferencesProvider);
|
||||
return CurrencyNotifier(prefs);
|
||||
},
|
||||
);
|
||||
|
||||
class ThemeModeNotifier extends StateNotifier<ThemeMode> {
|
||||
ThemeModeNotifier() : super(ThemeMode.dark) {
|
||||
final SharedPreferences _prefs;
|
||||
|
||||
ThemeModeNotifier(this._prefs) : super(ThemeMode.dark) {
|
||||
_load();
|
||||
}
|
||||
|
||||
void _load() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
state = (prefs.getBool('dark_mode') ?? true) ? ThemeMode.dark : ThemeMode.light;
|
||||
void _load() {
|
||||
state = (_prefs.getBool('dark_mode') ?? true) ? ThemeMode.dark : ThemeMode.light;
|
||||
}
|
||||
|
||||
Future<void> toggle() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
state = state == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
|
||||
await prefs.setBool('dark_mode', state == ThemeMode.dark);
|
||||
await _prefs.setBool('dark_mode', state == ThemeMode.dark);
|
||||
}
|
||||
|
||||
Future<void> setThemeMode(bool isDark) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
state = isDark ? ThemeMode.dark : ThemeMode.light;
|
||||
await prefs.setBool('dark_mode', isDark);
|
||||
await _prefs.setBool('dark_mode', isDark);
|
||||
}
|
||||
}
|
||||
|
||||
final themeProvider = StateNotifierProvider<ThemeModeNotifier, ThemeMode>(
|
||||
(ref) => ThemeModeNotifier(),
|
||||
(ref) {
|
||||
final prefs = ref.watch(sharedPreferencesProvider);
|
||||
return ThemeModeNotifier(prefs);
|
||||
},
|
||||
);
|
||||
|
||||
final exchangeRateServiceProvider = Provider<ExchangeRateService>((ref) {
|
||||
|
||||
Reference in New Issue
Block a user