mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-07-06 22:20:42 +00:00
_EnumsModel
-> _UserPreferencesModel
This commit is contained in:
parent
f9f22324db
commit
fd7a9d252a
1 changed files with 41 additions and 66 deletions
|
@ -22,15 +22,15 @@ class UserPreferencesProvider extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
static DynamicColorState dynamicColorStateOf(BuildContext context) {
|
static DynamicColorState dynamicColorStateOf(BuildContext context) {
|
||||||
return _inheritFromThemeModel(context, _ThemeAspect.dynamicColorState).dynamicColorState;
|
return _inheritFromEnumsModel(context, _Aspect.dynamicColorState).dynamicColorState;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EvSourceType evSourceTypeOf(BuildContext context) {
|
static EvSourceType evSourceTypeOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.evSourceType).evSourceType;
|
return _inheritFromEnumsModel(context, _Aspect.evSourceType).evSourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SupportedLocale localeOf(BuildContext context) {
|
static SupportedLocale localeOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.locale).locale;
|
return _inheritFromEnumsModel(context, _Aspect.locale).locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MeteringScreenLayoutConfig meteringScreenConfigOf(BuildContext context) {
|
static MeteringScreenLayoutConfig meteringScreenConfigOf(BuildContext context) {
|
||||||
|
@ -43,23 +43,22 @@ class UserPreferencesProvider extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
static StopType stopTypeOf(BuildContext context) {
|
static StopType stopTypeOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.stopType).stopType;
|
return _inheritFromEnumsModel(context, _Aspect.stopType).stopType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ThemeData themeOf(BuildContext context) {
|
static ThemeData themeOf(BuildContext context) {
|
||||||
return _inheritFromThemeModel(context, _ThemeAspect.theme).theme;
|
return _inheritFromEnumsModel(context, _Aspect.theme).theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ThemeType themeTypeOf(BuildContext context) {
|
static ThemeType themeTypeOf(BuildContext context) {
|
||||||
return _inheritFromThemeModel(context, _ThemeAspect.themeType).themeType;
|
return _inheritFromEnumsModel(context, _Aspect.themeType).themeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _EnumsModel _inheritFromEnumsModel(BuildContext context, _ListenableAspect aspect) {
|
static _UserPreferencesModel _inheritFromEnumsModel(
|
||||||
return InheritedModel.inheritFrom<_EnumsModel>(context, aspect: aspect)!;
|
BuildContext context,
|
||||||
}
|
_Aspect aspect,
|
||||||
|
) {
|
||||||
static _ThemeModel _inheritFromThemeModel(BuildContext context, _ThemeAspect aspect) {
|
return InheritedModel.inheritFrom<_UserPreferencesModel>(context, aspect: aspect)!;
|
||||||
return InheritedModel.inheritFrom<_ThemeModel>(context, aspect: aspect)!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -122,20 +121,18 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
dynamicPrimaryColor = null;
|
dynamicPrimaryColor = null;
|
||||||
state = DynamicColorState.unavailable;
|
state = DynamicColorState.unavailable;
|
||||||
}
|
}
|
||||||
return _ThemeModel(
|
return _UserPreferencesModel(
|
||||||
brightness: _themeBrightness,
|
brightness: _themeBrightness,
|
||||||
dynamicColorState: state,
|
dynamicColorState: state,
|
||||||
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
|
||||||
themeType: themeType,
|
|
||||||
child: _EnumsModel(
|
|
||||||
evSourceType: evSourceType,
|
evSourceType: evSourceType,
|
||||||
locale: locale,
|
locale: locale,
|
||||||
|
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
||||||
stopType: stopType,
|
stopType: stopType,
|
||||||
|
themeType: themeType,
|
||||||
child: _MeteringScreenLayoutModel(
|
child: _MeteringScreenLayoutModel(
|
||||||
data: meteringScreenLayout,
|
data: meteringScreenLayout,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -212,60 +209,32 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum _ListenableAspect {
|
enum _Aspect {
|
||||||
|
dynamicColorState,
|
||||||
evSourceType,
|
evSourceType,
|
||||||
locale,
|
locale,
|
||||||
stopType,
|
stopType,
|
||||||
}
|
|
||||||
|
|
||||||
class _EnumsModel extends InheritedModel<_ListenableAspect> {
|
|
||||||
final EvSourceType evSourceType;
|
|
||||||
final SupportedLocale locale;
|
|
||||||
final StopType stopType;
|
|
||||||
|
|
||||||
const _EnumsModel({
|
|
||||||
required this.evSourceType,
|
|
||||||
required this.locale,
|
|
||||||
required this.stopType,
|
|
||||||
required super.child,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(_EnumsModel oldWidget) {
|
|
||||||
return evSourceType != oldWidget.evSourceType ||
|
|
||||||
locale != oldWidget.locale ||
|
|
||||||
stopType != oldWidget.stopType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotifyDependent(
|
|
||||||
_EnumsModel oldWidget,
|
|
||||||
Set<_ListenableAspect> dependencies,
|
|
||||||
) {
|
|
||||||
return (evSourceType != oldWidget.evSourceType &&
|
|
||||||
dependencies.contains(_ListenableAspect.evSourceType)) ||
|
|
||||||
(locale != oldWidget.locale && dependencies.contains(_ListenableAspect.locale)) ||
|
|
||||||
(stopType != oldWidget.stopType && dependencies.contains(_ListenableAspect.stopType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum _ThemeAspect {
|
|
||||||
dynamicColorState,
|
|
||||||
theme,
|
theme,
|
||||||
themeType,
|
themeType,
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ThemeModel extends InheritedModel<_ThemeAspect> {
|
class _UserPreferencesModel extends InheritedModel<_Aspect> {
|
||||||
final DynamicColorState dynamicColorState;
|
final DynamicColorState dynamicColorState;
|
||||||
|
final EvSourceType evSourceType;
|
||||||
|
final SupportedLocale locale;
|
||||||
|
final StopType stopType;
|
||||||
final ThemeType themeType;
|
final ThemeType themeType;
|
||||||
|
|
||||||
final Brightness _brightness;
|
final Brightness _brightness;
|
||||||
final Color _primaryColor;
|
final Color _primaryColor;
|
||||||
|
|
||||||
const _ThemeModel({
|
const _UserPreferencesModel({
|
||||||
required Brightness brightness,
|
required Brightness brightness,
|
||||||
required this.dynamicColorState,
|
required this.dynamicColorState,
|
||||||
|
required this.evSourceType,
|
||||||
|
required this.locale,
|
||||||
required Color primaryColor,
|
required Color primaryColor,
|
||||||
|
required this.stopType,
|
||||||
required this.themeType,
|
required this.themeType,
|
||||||
required super.child,
|
required super.child,
|
||||||
}) : _brightness = brightness,
|
}) : _brightness = brightness,
|
||||||
|
@ -274,23 +243,29 @@ class _ThemeModel extends InheritedModel<_ThemeAspect> {
|
||||||
ThemeData get theme => themeFrom(_primaryColor, _brightness);
|
ThemeData get theme => themeFrom(_primaryColor, _brightness);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(_ThemeModel oldWidget) {
|
bool updateShouldNotify(_UserPreferencesModel oldWidget) {
|
||||||
return _brightness != oldWidget._brightness ||
|
return _brightness != oldWidget._brightness ||
|
||||||
dynamicColorState != oldWidget.dynamicColorState ||
|
dynamicColorState != oldWidget.dynamicColorState ||
|
||||||
|
evSourceType != oldWidget.evSourceType ||
|
||||||
|
locale != oldWidget.locale ||
|
||||||
_primaryColor != oldWidget._primaryColor ||
|
_primaryColor != oldWidget._primaryColor ||
|
||||||
|
stopType != oldWidget.stopType ||
|
||||||
themeType != oldWidget.themeType;
|
themeType != oldWidget.themeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotifyDependent(
|
bool updateShouldNotifyDependent(
|
||||||
_ThemeModel oldWidget,
|
_UserPreferencesModel oldWidget,
|
||||||
Set<_ThemeAspect> dependencies,
|
Set<_Aspect> dependencies,
|
||||||
) {
|
) {
|
||||||
return (dependencies.contains(_ThemeAspect.theme) &&
|
return (dependencies.contains(_Aspect.dynamicColorState) &&
|
||||||
(_brightness != oldWidget._brightness || _primaryColor != oldWidget._primaryColor)) ||
|
|
||||||
(dependencies.contains(_ThemeAspect.dynamicColorState) &&
|
|
||||||
dynamicColorState != oldWidget.dynamicColorState) ||
|
dynamicColorState != oldWidget.dynamicColorState) ||
|
||||||
(dependencies.contains(_ThemeAspect.themeType) && themeType != oldWidget.themeType);
|
(dependencies.contains(_Aspect.evSourceType) && evSourceType != oldWidget.evSourceType) ||
|
||||||
|
(dependencies.contains(_Aspect.locale) && locale != oldWidget.locale) ||
|
||||||
|
(dependencies.contains(_Aspect.stopType) && stopType != oldWidget.stopType) ||
|
||||||
|
(dependencies.contains(_Aspect.theme) &&
|
||||||
|
(_brightness != oldWidget._brightness || _primaryColor != oldWidget._primaryColor)) ||
|
||||||
|
(dependencies.contains(_Aspect.themeType) && themeType != oldWidget.themeType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue