mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 00:10:47 +00:00
cdf7372913
* wip * `MeteringScreenLayout = InheritedModelBase<MeteringScreenLayoutFeature, bool>` * removed `Provider` from providers folder * wip * Update pubspec.yaml * `context.get<MeteringInteractor>()` * `context.get<Environment>()` * `context.get<SettingsInteractor>()` * typo * fixed `MeteringScreenLayout` * fixed redundant vibrations
53 lines
1.5 KiB
Dart
53 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lightmeter/data/models/supported_locale.dart';
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
import 'package:lightmeter/generated/l10n.dart';
|
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
|
|
class SupportedLocaleProvider extends StatefulWidget {
|
|
final Widget child;
|
|
|
|
const SupportedLocaleProvider({required this.child, super.key});
|
|
|
|
static SupportedLocaleProviderState of(BuildContext context) {
|
|
return context.findAncestorStateOfType<SupportedLocaleProviderState>()!;
|
|
}
|
|
|
|
@override
|
|
State<SupportedLocaleProvider> createState() => SupportedLocaleProviderState();
|
|
}
|
|
|
|
class SupportedLocaleProviderState extends State<SupportedLocaleProvider> {
|
|
late final ValueNotifier<SupportedLocale> valueListenable;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
valueListenable = ValueNotifier(context.get<UserPreferencesService>().locale);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
valueListenable.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ValueListenableBuilder(
|
|
valueListenable: valueListenable,
|
|
builder: (_, value, child) => InheritedWidgetBase<SupportedLocale>(
|
|
data: value,
|
|
child: child!,
|
|
),
|
|
child: widget.child,
|
|
);
|
|
}
|
|
|
|
void setLocale(SupportedLocale locale) {
|
|
S.load(Locale(locale.intlName)).then((value) {
|
|
valueListenable.value = locale;
|
|
context.get<UserPreferencesService>().locale = locale;
|
|
});
|
|
}
|
|
}
|