Change prefs

This commit is contained in:
problematicconsumer
2023-09-07 13:43:46 +03:30
parent d52404a040
commit 854b522d97
10 changed files with 47 additions and 44 deletions

View File

@@ -13,7 +13,7 @@ class AppView extends HookConsumerWidget with PresLogger {
@override
Widget build(BuildContext context, WidgetRef ref) {
final router = ref.watch(routerProvider);
final locale = ref.watch(localeNotifierProvider).locale;
final locale = ref.watch(localeNotifierProvider).flutterLocale;
final theme = ref.watch(themeProvider);
ref.watch(commonControllersProvider);
@@ -21,7 +21,7 @@ class AppView extends HookConsumerWidget with PresLogger {
return MaterialApp.router(
routerConfig: router,
locale: locale,
supportedLocales: AppLocale.locales,
supportedLocales: AppLocaleUtils.supportedLocales,
localizationsDelegates: GlobalMaterialLocalizations.delegates,
debugShowCheckedModeBanner: false,
themeMode: theme.mode,

View File

@@ -5,7 +5,7 @@ part 'core_providers.g.dart';
@Riverpod(keepAlive: true)
TranslationsEn translations(TranslationsRef ref) =>
ref.watch(localeNotifierProvider).translations();
ref.watch(localeNotifierProvider).build();
@Riverpod(keepAlive: true)
AppTheme theme(ThemeRef ref) => AppTheme(

View File

@@ -1,5 +1,33 @@
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/utils/pref_notifier.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
final silentStartProvider = PrefNotifier.provider("silent_start", false);
part 'general_prefs.g.dart';
final debugModeProvider = PrefNotifier.provider("debug_mode", false);
@Riverpod(keepAlive: true)
class SilentStartNotifier extends _$SilentStartNotifier {
late final _pref =
Pref(ref.watch(sharedPreferencesProvider), "silent_start", false);
@override
bool build() => _pref.getValue();
Future<void> update(bool value) {
state = value;
return _pref.update(value);
}
}
@Riverpod(keepAlive: true)
class DebugModeNotifier extends _$DebugModeNotifier {
late final _pref =
Pref(ref.watch(sharedPreferencesProvider), "debug_mode", false);
@override
bool build() => _pref.getValue();
Future<void> update(bool value) {
state = value;
return _pref.update(value);
}
}

View File

@@ -1,5 +1,3 @@
import 'package:dartx/dartx.dart';
import 'package:flutter/widgets.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/gen/fonts.gen.dart';
import 'package:hiddify/gen/translations.g.dart';
@@ -24,32 +22,7 @@ class LocaleNotifier extends _$LocaleNotifier {
}
}
enum AppLocale {
en,
fa;
Locale get locale {
return Locale(name);
}
static List<Locale> get locales =>
AppLocale.values.map((e) => e.locale).toList();
static AppLocale fromString(String e) {
return AppLocale.values.firstOrNullWhere((element) => element.name == e) ??
AppLocale.en;
}
static AppLocale deviceLocale() {
return AppLocale.fromString(
AppLocaleUtils.findDeviceLocale().languageCode,
);
}
TranslationsEn translations() {
final appLocale = AppLocaleUtils.parse(name);
return appLocale.build();
}
String get preferredFontFamily => this == fa ? FontFamily.shabnam : "";
extension AppLocaleX on AppLocale {
String get preferredFontFamily =>
this == AppLocale.fa ? FontFamily.shabnam : "";
}