mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-09 07:28:14 -07:00
feature: Improved sync capability
This commit is contained in:
parent
f3e920ac79
commit
c5c7f71b84
31 changed files with 500 additions and 344 deletions
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:fladder/l10n/generated/app_localizations.dart';
|
||||
import 'package:fladder/providers/sync/background_download_provider.dart';
|
||||
|
||||
///Only use for base translations, under normal circumstances ALWAYS use the widgets provided context
|
||||
final localizationContextProvider = StateProvider<BuildContext?>((ref) => null);
|
||||
|
|
@ -13,7 +14,12 @@ extension BuildContextExtension on BuildContext {
|
|||
|
||||
class LocalizationContextWrapper extends ConsumerStatefulWidget {
|
||||
final Widget child;
|
||||
const LocalizationContextWrapper({required this.child, super.key});
|
||||
final Locale currentLocale;
|
||||
const LocalizationContextWrapper({
|
||||
required this.child,
|
||||
required this.currentLocale,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<LocalizationContextWrapper> createState() => _LocalizationContextWrapperState();
|
||||
|
|
@ -23,8 +29,21 @@ class _LocalizationContextWrapperState extends ConsumerState<LocalizationContext
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((event) {
|
||||
updateLanguageContext();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant LocalizationContextWrapper oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.currentLocale != widget.currentLocale) {
|
||||
updateLanguageContext();
|
||||
}
|
||||
}
|
||||
|
||||
void updateLanguageContext() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((value) {
|
||||
ref.read(localizationContextProvider.notifier).update((cb) => context);
|
||||
ref.read(backgroundDownloaderProvider.notifier).updateTranslations(context);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue