mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-04-20 23:22:07 +00:00
https://docs.flutter.dev/release/breaking-changes/flutter-generate-i10n-source The flutter tool will no longer generate a synthetic package:flutter_gen or modify the package_config.json of the app. Applications or tools that referenced package:flutter_gen should instead reference source files generated into the app's source directory directly.
46 lines
1.2 KiB
Dart
46 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mangayomi/main.dart';
|
|
import 'package:mangayomi/models/settings.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:mangayomi/l10n/generated/app_localizations.dart';
|
|
part 'l10n_providers.g.dart';
|
|
|
|
@riverpod
|
|
class L10nLocaleState extends _$L10nLocaleState {
|
|
@override
|
|
Locale build() {
|
|
return Locale(
|
|
_getLocale()!.languageCode ?? "en",
|
|
_getLocale()!.countryCode ?? "",
|
|
);
|
|
}
|
|
|
|
L10nLocale? _getLocale() {
|
|
return isar.settings.getSync(227)!.locale ??
|
|
L10nLocale(languageCode: "en", countryCode: "");
|
|
}
|
|
|
|
void setLocale(Locale locale) async {
|
|
final settings = isar.settings.getSync(227)!;
|
|
isar.writeTxnSync(() {
|
|
isar.settings.putSync(
|
|
settings
|
|
..locale = L10nLocale(
|
|
languageCode: locale.languageCode,
|
|
countryCode: locale.countryCode,
|
|
),
|
|
);
|
|
});
|
|
state = locale;
|
|
}
|
|
}
|
|
|
|
AppLocalizations? l10nLocalizations(BuildContext context) =>
|
|
AppLocalizations.of(context);
|
|
Locale currentLocale(BuildContext context) {
|
|
return Localizations.localeOf(context);
|
|
}
|
|
|
|
extension L10nExtension on BuildContext {
|
|
AppLocalizations get l10n => AppLocalizations.of(this)!;
|
|
}
|