mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-25 08:50:40 +00:00
Compare commits
No commits in common. "4ea92887417f3e03b63310891db12a25e290210f" and "e79226cfed79bd3cb2dfd14b7aa5a6f84c26ea91" have entirely different histories.
4ea9288741
...
e79226cfed
37 changed files with 575 additions and 488 deletions
|
@ -1,23 +1,14 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:lightmeter/data/caffeine_service.dart';
|
|
||||||
import 'package:lightmeter/data/haptics_service.dart';
|
|
||||||
import 'package:lightmeter/data/light_sensor_service.dart';
|
|
||||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
import 'package:lightmeter/data/models/supported_locale.dart';
|
||||||
import 'package:lightmeter/data/permissions_service.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
||||||
import 'package:lightmeter/data/volume_events_service.dart';
|
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
|
||||||
import 'package:lightmeter/res/theme.dart';
|
import 'package:lightmeter/res/theme.dart';
|
||||||
import 'package:lightmeter/screens/metering/flow_metering.dart';
|
import 'package:lightmeter/screens/metering/flow_metering.dart';
|
||||||
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
||||||
import 'package:platform/platform.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
class Application extends StatelessWidget {
|
class Application extends StatelessWidget {
|
||||||
final Environment env;
|
final Environment env;
|
||||||
|
@ -26,44 +17,28 @@ class Application extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder(
|
return LightmeterProviders(
|
||||||
future: Future.wait([
|
env: env,
|
||||||
SharedPreferences.getInstance(),
|
builder: (context, ready) {
|
||||||
const LightSensorService(LocalPlatform()).hasSensor(),
|
if (ready) {
|
||||||
]),
|
|
||||||
builder: (_, snapshot) {
|
|
||||||
if (snapshot.data != null) {
|
|
||||||
return ServicesProvider(
|
|
||||||
caffeineService: const CaffeineService(),
|
|
||||||
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
|
||||||
hapticsService: const HapticsService(),
|
|
||||||
lightSensorService: const LightSensorService(LocalPlatform()),
|
|
||||||
permissionsService: const PermissionsService(),
|
|
||||||
userPreferencesService: UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
|
||||||
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
|
||||||
child: UserPreferencesProvider(
|
|
||||||
child: EquipmentProfileProvider(
|
|
||||||
child: Builder(
|
|
||||||
builder: (context) {
|
|
||||||
final theme = themeFrom(
|
final theme = themeFrom(
|
||||||
UserPreferencesProvider.primaryColorOf(context),
|
EnumProviders.primaryColorOf(context),
|
||||||
UserPreferencesProvider.brightnessOf(context),
|
EnumProviders.brightnessOf(context),
|
||||||
);
|
);
|
||||||
final systemIconsBrightness =
|
final systemIconsBrightness =
|
||||||
ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface);
|
ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface);
|
||||||
return AnnotatedRegion(
|
return AnnotatedRegion(
|
||||||
value: SystemUiOverlayStyle(
|
value: SystemUiOverlayStyle(
|
||||||
statusBarColor: Colors.transparent,
|
statusBarColor: Colors.transparent,
|
||||||
statusBarBrightness: systemIconsBrightness == Brightness.light
|
statusBarBrightness:
|
||||||
? Brightness.dark
|
systemIconsBrightness == Brightness.light ? Brightness.dark : Brightness.light,
|
||||||
: Brightness.light,
|
|
||||||
statusBarIconBrightness: systemIconsBrightness,
|
statusBarIconBrightness: systemIconsBrightness,
|
||||||
systemNavigationBarColor: Colors.transparent,
|
systemNavigationBarColor: Colors.transparent,
|
||||||
systemNavigationBarIconBrightness: systemIconsBrightness,
|
systemNavigationBarIconBrightness: systemIconsBrightness,
|
||||||
),
|
),
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
theme: theme,
|
theme: theme,
|
||||||
locale: Locale(UserPreferencesProvider.localeOf(context).intlName),
|
locale: Locale(EnumProviders.localeOf(context).intlName),
|
||||||
localizationsDelegates: const [
|
localizationsDelegates: const [
|
||||||
S.delegate,
|
S.delegate,
|
||||||
GlobalMaterialLocalizations.delegate,
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
@ -82,17 +57,9 @@ class Application extends StatelessWidget {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
} else {
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (snapshot.error != null) {
|
|
||||||
return Center(child: Text(snapshot.error!.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(@vodemn): maybe user splashscreen instead
|
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
56
lib/providers.dart
Normal file
56
lib/providers.dart
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:lightmeter/data/caffeine_service.dart';
|
||||||
|
import 'package:lightmeter/data/haptics_service.dart';
|
||||||
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
||||||
|
import 'package:lightmeter/data/permissions_service.dart';
|
||||||
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
|
import 'package:lightmeter/data/volume_events_service.dart';
|
||||||
|
import 'package:lightmeter/environment.dart';
|
||||||
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
|
import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
||||||
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
|
import 'package:platform/platform.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class LightmeterProviders extends StatelessWidget {
|
||||||
|
final Environment env;
|
||||||
|
final Widget Function(BuildContext context, bool ready) builder;
|
||||||
|
|
||||||
|
const LightmeterProviders({required this.env, required this.builder, super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return FutureBuilder(
|
||||||
|
future: Future.wait([
|
||||||
|
SharedPreferences.getInstance(),
|
||||||
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
||||||
|
]),
|
||||||
|
builder: (_, snapshot) {
|
||||||
|
if (snapshot.data != null) {
|
||||||
|
return ServiceProviders(
|
||||||
|
caffeineService: const CaffeineService(),
|
||||||
|
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
||||||
|
hapticsService: const HapticsService(),
|
||||||
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
||||||
|
permissionsService: const PermissionsService(),
|
||||||
|
userPreferencesService: UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
||||||
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
||||||
|
child: EnumProviders(
|
||||||
|
child: MeteringScreenLayoutProvider(
|
||||||
|
child: EquipmentProfileProvider(
|
||||||
|
child: Builder(
|
||||||
|
builder: (context) => builder(context, true),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else if (snapshot.error != null) {
|
||||||
|
return Center(child: Text(snapshot.error!.toString()));
|
||||||
|
}
|
||||||
|
return builder(context, false);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,80 +3,74 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
||||||
import 'package:lightmeter/data/models/ev_source_type.dart';
|
import 'package:lightmeter/data/models/ev_source_type.dart';
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
|
||||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
import 'package:lightmeter/data/models/supported_locale.dart';
|
||||||
import 'package:lightmeter/data/models/theme_type.dart';
|
import 'package:lightmeter/data/models/theme_type.dart';
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class UserPreferencesProvider extends StatefulWidget {
|
enum _ListenableAspect {
|
||||||
|
brightness,
|
||||||
|
dynamicColorState,
|
||||||
|
evSourceType,
|
||||||
|
locale,
|
||||||
|
primaryColor,
|
||||||
|
stopType,
|
||||||
|
themeType,
|
||||||
|
}
|
||||||
|
|
||||||
|
class EnumProviders extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
const UserPreferencesProvider({required this.child, super.key});
|
const EnumProviders({required this.child, super.key});
|
||||||
|
|
||||||
static _UserPreferencesProviderState of(BuildContext context) {
|
static _EnumProvidersState of(BuildContext context) {
|
||||||
return context.findAncestorStateOfType<_UserPreferencesProviderState>()!;
|
return context.findAncestorStateOfType<_EnumProvidersState>()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Brightness brightnessOf(BuildContext context) {
|
static Brightness brightnessOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.brightness).brightness;
|
return _inheritFrom(context, _ListenableAspect.brightness).brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DynamicColorState dynamicColorStateOf(BuildContext context) {
|
static DynamicColorState dynamicColorStateOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.dynamicColorState).dynamicColorState;
|
return _inheritFrom(context, _ListenableAspect.dynamicColorState).dynamicColorState;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EvSourceType evSourceTypeOf(BuildContext context) {
|
static EvSourceType evSourceTypeOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.evSourceType).evSourceType;
|
return _inheritFrom(context, _ListenableAspect.evSourceType).evSourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SupportedLocale localeOf(BuildContext context) {
|
static SupportedLocale localeOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.locale).locale;
|
return _inheritFrom(context, _ListenableAspect.locale).locale;
|
||||||
}
|
|
||||||
|
|
||||||
static MeteringScreenLayoutConfig meteringScreenConfigOf(BuildContext context) {
|
|
||||||
return context.findAncestorWidgetOfExactType<_MeteringScreenLayoutModel>()!.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool meteringScreenFeatureOf(BuildContext context, MeteringScreenLayoutFeature feature) {
|
|
||||||
return InheritedModel.inheritFrom<_MeteringScreenLayoutModel>(context, aspect: feature)!
|
|
||||||
.data[feature]!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color primaryColorOf(BuildContext context) {
|
static Color primaryColorOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.primaryColor).primaryColor;
|
return _inheritFrom(context, _ListenableAspect.primaryColor).primaryColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static StopType stopTypeOf(BuildContext context) {
|
static StopType stopTypeOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.stopType).stopType;
|
return _inheritFrom(context, _ListenableAspect.stopType).stopType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ThemeType themeTypeOf(BuildContext context) {
|
static ThemeType themeTypeOf(BuildContext context) {
|
||||||
return _inheritFromEnumsModel(context, _ListenableAspect.themeType).themeType;
|
return _inheritFrom(context, _ListenableAspect.themeType).themeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _EnumsModel _inheritFromEnumsModel(
|
static _EnumProvidersModel _inheritFrom(BuildContext context, _ListenableAspect aspect) {
|
||||||
BuildContext context,
|
return InheritedModel.inheritFrom<_EnumProvidersModel>(context, aspect: aspect)!;
|
||||||
_ListenableAspect aspect,
|
|
||||||
) {
|
|
||||||
return InheritedModel.inheritFrom<_EnumsModel>(context, aspect: aspect)!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<UserPreferencesProvider> createState() => _UserPreferencesProviderState();
|
State<EnumProviders> createState() => _EnumProvidersState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
class _EnumProvidersState extends State<EnumProviders> with WidgetsBindingObserver {
|
||||||
with WidgetsBindingObserver {
|
|
||||||
UserPreferencesService get userPreferencesService =>
|
UserPreferencesService get userPreferencesService =>
|
||||||
ServicesProvider.of(context).userPreferencesService;
|
ServiceProviders.userPreferencesServiceOf(context);
|
||||||
|
|
||||||
late bool dynamicColor = userPreferencesService.dynamicColor;
|
late bool dynamicColor = userPreferencesService.dynamicColor;
|
||||||
late EvSourceType evSourceType;
|
late EvSourceType evSourceType;
|
||||||
late final MeteringScreenLayoutConfig meteringScreenLayout =
|
|
||||||
ServicesProvider.of(context).userPreferencesService.meteringScreenLayout;
|
|
||||||
late Color primaryColor = userPreferencesService.primaryColor;
|
late Color primaryColor = userPreferencesService.primaryColor;
|
||||||
late StopType stopType = userPreferencesService.stopType;
|
late StopType stopType = userPreferencesService.stopType;
|
||||||
late SupportedLocale locale = userPreferencesService.locale;
|
late SupportedLocale locale = userPreferencesService.locale;
|
||||||
|
@ -85,9 +79,9 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
evSourceType = ServicesProvider.of(context).userPreferencesService.evSourceType;
|
evSourceType = ServiceProviders.userPreferencesServiceOf(context).evSourceType;
|
||||||
evSourceType = evSourceType == EvSourceType.sensor &&
|
evSourceType = evSourceType == EvSourceType.sensor &&
|
||||||
!ServicesProvider.of(context).environment.hasLightSensor
|
!ServiceProviders.environmentOf(context).hasLightSensor
|
||||||
? EvSourceType.camera
|
? EvSourceType.camera
|
||||||
: evSourceType;
|
: evSourceType;
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
@ -124,7 +118,7 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
dynamicPrimaryColor = null;
|
dynamicPrimaryColor = null;
|
||||||
state = DynamicColorState.unavailable;
|
state = DynamicColorState.unavailable;
|
||||||
}
|
}
|
||||||
return _EnumsModel(
|
return _EnumProvidersModel(
|
||||||
brightness: _themeBrightness,
|
brightness: _themeBrightness,
|
||||||
dynamicColorState: state,
|
dynamicColorState: state,
|
||||||
evSourceType: evSourceType,
|
evSourceType: evSourceType,
|
||||||
|
@ -132,10 +126,7 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
||||||
stopType: stopType,
|
stopType: stopType,
|
||||||
themeType: themeType,
|
themeType: themeType,
|
||||||
child: _MeteringScreenLayoutModel(
|
|
||||||
data: meteringScreenLayout,
|
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -145,11 +136,11 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
setState(() {
|
setState(() {
|
||||||
dynamicColor = enable;
|
dynamicColor = enable;
|
||||||
});
|
});
|
||||||
ServicesProvider.of(context).userPreferencesService.dynamicColor = enable;
|
ServiceProviders.userPreferencesServiceOf(context).dynamicColor = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleEvSourceType() {
|
void toggleEvSourceType() {
|
||||||
if (!ServicesProvider.of(context).environment.hasLightSensor) {
|
if (!ServiceProviders.environmentOf(context).hasLightSensor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -160,7 +151,7 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
evSourceType = EvSourceType.camera;
|
evSourceType = EvSourceType.camera;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ServicesProvider.of(context).userPreferencesService.evSourceType = evSourceType;
|
ServiceProviders.userPreferencesServiceOf(context).evSourceType = evSourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLocale(SupportedLocale locale) {
|
void setLocale(SupportedLocale locale) {
|
||||||
|
@ -168,42 +159,29 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
setState(() {
|
setState(() {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
});
|
});
|
||||||
ServicesProvider.of(context).userPreferencesService.locale = locale;
|
ServiceProviders.userPreferencesServiceOf(context).locale = locale;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMeteringScreenLayout(MeteringScreenLayoutConfig config) {
|
|
||||||
setState(() {
|
|
||||||
config.forEach((key, value) {
|
|
||||||
meteringScreenLayout.update(
|
|
||||||
key,
|
|
||||||
(_) => value,
|
|
||||||
ifAbsent: () => value,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
ServicesProvider.of(context).userPreferencesService.meteringScreenLayout = meteringScreenLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPrimaryColor(Color primaryColor) {
|
void setPrimaryColor(Color primaryColor) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.primaryColor = primaryColor;
|
this.primaryColor = primaryColor;
|
||||||
});
|
});
|
||||||
ServicesProvider.of(context).userPreferencesService.primaryColor = primaryColor;
|
ServiceProviders.userPreferencesServiceOf(context).primaryColor = primaryColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStopType(StopType stopType) {
|
void setStopType(StopType stopType) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.stopType = stopType;
|
this.stopType = stopType;
|
||||||
});
|
});
|
||||||
ServicesProvider.of(context).userPreferencesService.stopType = stopType;
|
ServiceProviders.userPreferencesServiceOf(context).stopType = stopType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setThemeType(ThemeType themeType) {
|
void setThemeType(ThemeType themeType) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.themeType = themeType;
|
this.themeType = themeType;
|
||||||
});
|
});
|
||||||
ServicesProvider.of(context).userPreferencesService.themeType = themeType;
|
ServiceProviders.userPreferencesServiceOf(context).themeType = themeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Brightness get _themeBrightness {
|
Brightness get _themeBrightness {
|
||||||
|
@ -218,17 +196,7 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum _ListenableAspect {
|
class _EnumProvidersModel extends InheritedModel<_ListenableAspect> {
|
||||||
brightness,
|
|
||||||
dynamicColorState,
|
|
||||||
evSourceType,
|
|
||||||
locale,
|
|
||||||
primaryColor,
|
|
||||||
stopType,
|
|
||||||
themeType,
|
|
||||||
}
|
|
||||||
|
|
||||||
class _EnumsModel extends InheritedModel<_ListenableAspect> {
|
|
||||||
final Brightness brightness;
|
final Brightness brightness;
|
||||||
final DynamicColorState dynamicColorState;
|
final DynamicColorState dynamicColorState;
|
||||||
final EvSourceType evSourceType;
|
final EvSourceType evSourceType;
|
||||||
|
@ -237,7 +205,7 @@ class _EnumsModel extends InheritedModel<_ListenableAspect> {
|
||||||
final StopType stopType;
|
final StopType stopType;
|
||||||
final ThemeType themeType;
|
final ThemeType themeType;
|
||||||
|
|
||||||
const _EnumsModel({
|
const _EnumProvidersModel({
|
||||||
required this.brightness,
|
required this.brightness,
|
||||||
required this.dynamicColorState,
|
required this.dynamicColorState,
|
||||||
required this.evSourceType,
|
required this.evSourceType,
|
||||||
|
@ -249,7 +217,7 @@ class _EnumsModel extends InheritedModel<_ListenableAspect> {
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(_EnumsModel oldWidget) {
|
bool updateShouldNotify(_EnumProvidersModel oldWidget) {
|
||||||
return brightness != oldWidget.brightness ||
|
return brightness != oldWidget.brightness ||
|
||||||
dynamicColorState != oldWidget.dynamicColorState ||
|
dynamicColorState != oldWidget.dynamicColorState ||
|
||||||
evSourceType != oldWidget.evSourceType ||
|
evSourceType != oldWidget.evSourceType ||
|
||||||
|
@ -261,7 +229,7 @@ class _EnumsModel extends InheritedModel<_ListenableAspect> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotifyDependent(
|
bool updateShouldNotifyDependent(
|
||||||
_EnumsModel oldWidget,
|
_EnumProvidersModel oldWidget,
|
||||||
Set<_ListenableAspect> dependencies,
|
Set<_ListenableAspect> dependencies,
|
||||||
) {
|
) {
|
||||||
return (brightness != oldWidget.brightness &&
|
return (brightness != oldWidget.brightness &&
|
||||||
|
@ -277,28 +245,3 @@ class _EnumsModel extends InheritedModel<_ListenableAspect> {
|
||||||
(themeType != oldWidget.themeType && dependencies.contains(_ListenableAspect.themeType));
|
(themeType != oldWidget.themeType && dependencies.contains(_ListenableAspect.themeType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MeteringScreenLayoutModel extends InheritedModel<MeteringScreenLayoutFeature> {
|
|
||||||
final Map<MeteringScreenLayoutFeature, bool> data;
|
|
||||||
|
|
||||||
const _MeteringScreenLayoutModel({
|
|
||||||
required this.data,
|
|
||||||
required super.child,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(_MeteringScreenLayoutModel oldWidget) => oldWidget.data != data;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotifyDependent(
|
|
||||||
_MeteringScreenLayoutModel oldWidget,
|
|
||||||
Set<MeteringScreenLayoutFeature> dependencies,
|
|
||||||
) {
|
|
||||||
for (final dependecy in dependencies) {
|
|
||||||
if (oldWidget.data[dependecy] != data[dependecy]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,11 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
// TODO(@vodemn): This will be removed in #89
|
typedef EquipmentProfiles = List<EquipmentProfile>;
|
||||||
|
|
||||||
class EquipmentProfileProvider extends StatefulWidget {
|
class EquipmentProfileProvider extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
|
@ -33,7 +35,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
EquipmentProfile get _selectedProfile => _customProfiles.firstWhere(
|
EquipmentProfile get _selectedProfile => _customProfiles.firstWhere(
|
||||||
(e) => e.id == _selectedId,
|
(e) => e.id == _selectedId,
|
||||||
orElse: () {
|
orElse: () {
|
||||||
ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId =
|
ServiceProviders.userPreferencesServiceOf(context).selectedEquipmentProfileId =
|
||||||
_defaultProfile.id;
|
_defaultProfile.id;
|
||||||
return _defaultProfile;
|
return _defaultProfile;
|
||||||
},
|
},
|
||||||
|
@ -42,16 +44,18 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_selectedId = ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId;
|
_selectedId = ServiceProviders.userPreferencesServiceOf(context).selectedEquipmentProfileId;
|
||||||
_customProfiles = ServicesProvider.of(context).userPreferencesService.equipmentProfiles;
|
_customProfiles = ServiceProviders.userPreferencesServiceOf(context).equipmentProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return EquipmentProfiles(
|
return InheritedWidgetBase<List<EquipmentProfile>>(
|
||||||
profiles: [_defaultProfile] + _customProfiles,
|
data: [_defaultProfile] + _customProfiles,
|
||||||
selected: _selectedProfile,
|
child: InheritedWidgetBase<EquipmentProfile>(
|
||||||
|
data: _selectedProfile,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +63,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedId = data.id;
|
_selectedId = data.id;
|
||||||
});
|
});
|
||||||
ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId =
|
ServiceProviders.userPreferencesServiceOf(context).selectedEquipmentProfileId =
|
||||||
_selectedProfile.id;
|
_selectedProfile.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,48 +96,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _refreshSavedProfiles() {
|
void _refreshSavedProfiles() {
|
||||||
ServicesProvider.of(context).userPreferencesService.equipmentProfiles = _customProfiles;
|
ServiceProviders.userPreferencesServiceOf(context).equipmentProfiles = _customProfiles;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from #89
|
|
||||||
enum EquipmentProfilesAspect { list, selected }
|
|
||||||
|
|
||||||
class EquipmentProfiles extends InheritedModel<EquipmentProfilesAspect> {
|
|
||||||
const EquipmentProfiles({
|
|
||||||
super.key,
|
|
||||||
required this.profiles,
|
|
||||||
required this.selected,
|
|
||||||
required super.child,
|
|
||||||
});
|
|
||||||
|
|
||||||
final List<EquipmentProfile> profiles;
|
|
||||||
final EquipmentProfile selected;
|
|
||||||
|
|
||||||
static List<EquipmentProfile> of(BuildContext context) {
|
|
||||||
return InheritedModel.inheritFrom<EquipmentProfiles>(
|
|
||||||
context,
|
|
||||||
aspect: EquipmentProfilesAspect.list,
|
|
||||||
)!
|
|
||||||
.profiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
static EquipmentProfile selectedOf(BuildContext context) {
|
|
||||||
return InheritedModel.inheritFrom<EquipmentProfiles>(
|
|
||||||
context,
|
|
||||||
aspect: EquipmentProfilesAspect.selected,
|
|
||||||
)!
|
|
||||||
.selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(EquipmentProfiles oldWidget) => false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotifyDependent(
|
|
||||||
EquipmentProfiles oldWidget,
|
|
||||||
Set<EquipmentProfilesAspect> dependencies,
|
|
||||||
) =>
|
|
||||||
false;
|
|
||||||
}
|
|
||||||
|
|
60
lib/providers/metering_screen_layout_provider.dart
Normal file
60
lib/providers/metering_screen_layout_provider.dart
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
|
class MeteringScreenLayoutProvider extends StatefulWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const MeteringScreenLayoutProvider({required this.child, super.key});
|
||||||
|
|
||||||
|
static MeteringScreenLayoutProviderState of(BuildContext context) {
|
||||||
|
return context.findAncestorStateOfType<MeteringScreenLayoutProviderState>()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MeteringScreenLayoutProvider> createState() => MeteringScreenLayoutProviderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class MeteringScreenLayoutProviderState extends State<MeteringScreenLayoutProvider> {
|
||||||
|
late final MeteringScreenLayoutConfig _config =
|
||||||
|
ServiceProviders.userPreferencesServiceOf(context).meteringScreenLayout;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return InheritedModelBase<MeteringScreenLayoutFeature, bool>(
|
||||||
|
data: MeteringScreenLayoutConfig.from(_config),
|
||||||
|
child: widget.child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateFeatures(MeteringScreenLayoutConfig config) {
|
||||||
|
setState(() {
|
||||||
|
config.forEach((key, value) {
|
||||||
|
_config.update(
|
||||||
|
key,
|
||||||
|
(_) => value,
|
||||||
|
ifAbsent: () => value,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ServiceProviders.userPreferencesServiceOf(context).meteringScreenLayout = _config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef _MeteringScreenLayoutModel = InheritedModelBase<MeteringScreenLayoutFeature, bool>;
|
||||||
|
|
||||||
|
extension MeteringScreenLayout on InheritedModelBase<MeteringScreenLayoutFeature, bool> {
|
||||||
|
static MeteringScreenLayoutConfig of(BuildContext context, {bool listen = true}) {
|
||||||
|
if (listen) {
|
||||||
|
return context.dependOnInheritedWidgetOfExactType<_MeteringScreenLayoutModel>()!.data;
|
||||||
|
} else {
|
||||||
|
return context.findAncestorWidgetOfExactType<_MeteringScreenLayoutModel>()!.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool featureOf(BuildContext context, MeteringScreenLayoutFeature aspect) {
|
||||||
|
return InheritedModel.inheritFrom<_MeteringScreenLayoutModel>(context, aspect: aspect)!
|
||||||
|
.data[aspect]!;
|
||||||
|
}
|
||||||
|
}
|
64
lib/providers/service_providers.dart
Normal file
64
lib/providers/service_providers.dart
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:lightmeter/data/caffeine_service.dart';
|
||||||
|
import 'package:lightmeter/data/haptics_service.dart';
|
||||||
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
||||||
|
import 'package:lightmeter/data/permissions_service.dart';
|
||||||
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
|
import 'package:lightmeter/data/volume_events_service.dart';
|
||||||
|
import 'package:lightmeter/environment.dart';
|
||||||
|
|
||||||
|
class ServiceProviders extends InheritedWidget {
|
||||||
|
final CaffeineService caffeineService;
|
||||||
|
final Environment environment;
|
||||||
|
final HapticsService hapticsService;
|
||||||
|
final LightSensorService lightSensorService;
|
||||||
|
final PermissionsService permissionsService;
|
||||||
|
final UserPreferencesService userPreferencesService;
|
||||||
|
final VolumeEventsService volumeEventsService;
|
||||||
|
|
||||||
|
const ServiceProviders({
|
||||||
|
required this.caffeineService,
|
||||||
|
required this.environment,
|
||||||
|
required this.hapticsService,
|
||||||
|
required this.lightSensorService,
|
||||||
|
required this.permissionsService,
|
||||||
|
required this.userPreferencesService,
|
||||||
|
required this.volumeEventsService,
|
||||||
|
required super.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
static CaffeineService caffeineServiceOf(BuildContext context) {
|
||||||
|
return ServiceProviders._of(context).caffeineService;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Environment environmentOf(BuildContext context) {
|
||||||
|
return ServiceProviders._of(context).environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HapticsService hapticsServiceOf(BuildContext context) {
|
||||||
|
return ServiceProviders._of(context).hapticsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
static LightSensorService lightSensorServiceOf(BuildContext context) {
|
||||||
|
return ServiceProviders._of(context).lightSensorService;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PermissionsService permissionsServiceOf(BuildContext context) {
|
||||||
|
return ServiceProviders._of(context).permissionsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
static UserPreferencesService userPreferencesServiceOf(BuildContext context) {
|
||||||
|
return ServiceProviders._of(context).userPreferencesService;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VolumeEventsService volumeEventsServiceOf(BuildContext context) {
|
||||||
|
return ServiceProviders._of(context).volumeEventsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ServiceProviders _of(BuildContext context) {
|
||||||
|
return context.findAncestorWidgetOfExactType<ServiceProviders>()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(ServiceProviders oldWidget) => false;
|
||||||
|
}
|
|
@ -1,36 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:lightmeter/data/caffeine_service.dart';
|
|
||||||
import 'package:lightmeter/data/haptics_service.dart';
|
|
||||||
import 'package:lightmeter/data/light_sensor_service.dart';
|
|
||||||
import 'package:lightmeter/data/permissions_service.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
||||||
import 'package:lightmeter/data/volume_events_service.dart';
|
|
||||||
import 'package:lightmeter/environment.dart';
|
|
||||||
|
|
||||||
class ServicesProvider extends InheritedWidget {
|
|
||||||
final CaffeineService caffeineService;
|
|
||||||
final Environment environment;
|
|
||||||
final HapticsService hapticsService;
|
|
||||||
final LightSensorService lightSensorService;
|
|
||||||
final PermissionsService permissionsService;
|
|
||||||
final UserPreferencesService userPreferencesService;
|
|
||||||
final VolumeEventsService volumeEventsService;
|
|
||||||
|
|
||||||
const ServicesProvider({
|
|
||||||
required this.caffeineService,
|
|
||||||
required this.environment,
|
|
||||||
required this.hapticsService,
|
|
||||||
required this.lightSensorService,
|
|
||||||
required this.permissionsService,
|
|
||||||
required this.userPreferencesService,
|
|
||||||
required this.volumeEventsService,
|
|
||||||
required super.child,
|
|
||||||
});
|
|
||||||
|
|
||||||
static ServicesProvider of(BuildContext context) {
|
|
||||||
return context.findAncestorWidgetOfExactType<ServicesProvider>()!;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(ServicesProvider oldWidget) => false;
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/ev_source_type.dart';
|
import 'package:lightmeter/data/models/ev_source_type.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
|
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class MeteringBottomControls extends StatelessWidget {
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
onPressed: onSwitchEvSourceType,
|
onPressed: onSwitchEvSourceType,
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
UserPreferencesProvider.evSourceTypeOf(context) != EvSourceType.camera
|
EnumProviders.evSourceTypeOf(context) != EvSourceType.camera
|
||||||
? Icons.camera_rear
|
? Icons.camera_rear
|
||||||
: Icons.wb_incandescent,
|
: Icons.wb_incandescent,
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'package:camera/camera.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:lightmeter/platform_config.dart';
|
import 'package:lightmeter/platform_config.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/components/camera_preview/components/camera_view/widget_camera_view.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/components/camera_preview/components/camera_view/widget_camera_view.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/components/camera_preview/components/camera_view_placeholder/widget_placeholder_camera_view.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/components/camera_preview/components/camera_view_placeholder/widget_placeholder_camera_view.dart';
|
||||||
|
@ -38,7 +38,7 @@ class _CameraPreviewState extends State<CameraPreview> {
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
children: [
|
children: [
|
||||||
CameraView(controller: widget.controller!),
|
CameraView(controller: widget.controller!),
|
||||||
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.histogram,
|
MeteringScreenLayoutFeature.histogram,
|
||||||
))
|
))
|
||||||
|
|
|
@ -2,11 +2,12 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||||
import 'package:lightmeter/data/models/film.dart';
|
import 'package:lightmeter/data/models/film.dart';
|
||||||
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/bloc_container_camera.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/bloc_container_camera.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/event_container_camera.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/event_container_camera.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/widget_container_camera.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/widget_container_camera.dart';
|
||||||
import 'package:lightmeter/screens/metering/flow_metering.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class CameraContainerProvider extends StatelessWidget {
|
class CameraContainerProvider extends StatelessWidget {
|
||||||
|
@ -38,7 +39,7 @@ class CameraContainerProvider extends StatelessWidget {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => CameraContainerBloc(
|
create: (context) => CameraContainerBloc(
|
||||||
MeteringInteractorProvider.of(context),
|
context.get<MeteringInteractor>(),
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
)..add(const RequestPermissionEvent()),
|
)..add(const RequestPermissionEvent()),
|
||||||
child: CameraContainer(
|
child: CameraContainer(
|
||||||
|
|
|
@ -7,7 +7,7 @@ import 'package:lightmeter/data/models/film.dart';
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:lightmeter/features.dart';
|
import 'package:lightmeter/features.dart';
|
||||||
import 'package:lightmeter/platform_config.dart';
|
import 'package:lightmeter/platform_config.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/bloc_container_camera.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/bloc_container_camera.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/components/camera_controls/widget_camera_controls.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/components/camera_controls/widget_camera_controls.dart';
|
||||||
|
@ -114,14 +114,14 @@ class CameraContainer extends StatelessWidget {
|
||||||
enabledFeaturesHeight += Dimens.readingContainerSingleValueHeight;
|
enabledFeaturesHeight += Dimens.readingContainerSingleValueHeight;
|
||||||
enabledFeaturesHeight += Dimens.paddingS;
|
enabledFeaturesHeight += Dimens.paddingS;
|
||||||
}
|
}
|
||||||
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs,
|
MeteringScreenLayoutFeature.extremeExposurePairs,
|
||||||
)) {
|
)) {
|
||||||
enabledFeaturesHeight += Dimens.readingContainerDoubleValueHeight;
|
enabledFeaturesHeight += Dimens.readingContainerDoubleValueHeight;
|
||||||
enabledFeaturesHeight += Dimens.paddingS;
|
enabledFeaturesHeight += Dimens.paddingS;
|
||||||
}
|
}
|
||||||
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.filmPicker,
|
MeteringScreenLayoutFeature.filmPicker,
|
||||||
)) {
|
)) {
|
||||||
|
|
|
@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||||
import 'package:lightmeter/data/models/film.dart';
|
import 'package:lightmeter/data/models/film.dart';
|
||||||
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart';
|
import 'package:lightmeter/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/light_sensor_container/widget_container_light_sensor.dart';
|
import 'package:lightmeter/screens/metering/components/light_sensor_container/widget_container_light_sensor.dart';
|
||||||
import 'package:lightmeter/screens/metering/flow_metering.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class LightSensorContainerProvider extends StatelessWidget {
|
class LightSensorContainerProvider extends StatelessWidget {
|
||||||
|
@ -37,7 +38,7 @@ class LightSensorContainerProvider extends StatelessWidget {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => LightSensorContainerBloc(
|
create: (context) => LightSensorContainerBloc(
|
||||||
MeteringInteractorProvider.of(context),
|
context.get<MeteringInteractor>(),
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
),
|
),
|
||||||
child: LightSensorContainer(
|
child: LightSensorContainer(
|
||||||
|
|
|
@ -5,10 +5,11 @@ import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:lightmeter/features.dart';
|
import 'package:lightmeter/features.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart';
|
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/reading_value_container/widget_container_reading_value.dart';
|
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/reading_value_container/widget_container_reading_value.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class ReadingsContainer extends StatelessWidget {
|
class ReadingsContainer extends StatelessWidget {
|
||||||
|
@ -42,7 +43,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
const _EquipmentProfilePicker(),
|
const _EquipmentProfilePicker(),
|
||||||
const _InnerPadding(),
|
const _InnerPadding(),
|
||||||
],
|
],
|
||||||
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs,
|
MeteringScreenLayoutFeature.extremeExposurePairs,
|
||||||
)) ...[
|
)) ...[
|
||||||
|
@ -60,7 +61,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const _InnerPadding(),
|
const _InnerPadding(),
|
||||||
],
|
],
|
||||||
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.filmPicker,
|
MeteringScreenLayoutFeature.filmPicker,
|
||||||
)) ...[
|
)) ...[
|
||||||
|
@ -76,7 +77,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _IsoValuePicker(
|
child: _IsoValuePicker(
|
||||||
selectedValue: iso,
|
selectedValue: iso,
|
||||||
values: EquipmentProfiles.selectedOf(context).isoValues,
|
values: context.listen<EquipmentProfile>().isoValues,
|
||||||
onChanged: onIsoChanged,
|
onChanged: onIsoChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -84,7 +85,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _NdValuePicker(
|
child: _NdValuePicker(
|
||||||
selectedValue: nd,
|
selectedValue: nd,
|
||||||
values: EquipmentProfiles.selectedOf(context).ndValues,
|
values: context.listen<EquipmentProfile>().ndValues,
|
||||||
onChanged: onNdChanged,
|
onChanged: onNdChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -107,16 +108,16 @@ class _EquipmentProfilePicker extends StatelessWidget {
|
||||||
return AnimatedDialogPicker<EquipmentProfile>(
|
return AnimatedDialogPicker<EquipmentProfile>(
|
||||||
icon: Icons.camera,
|
icon: Icons.camera,
|
||||||
title: S.of(context).equipmentProfile,
|
title: S.of(context).equipmentProfile,
|
||||||
selectedValue: EquipmentProfiles.selectedOf(context),
|
selectedValue: context.listen<EquipmentProfile>(),
|
||||||
values: EquipmentProfiles.of(context),
|
values: context.listen<EquipmentProfiles>(),
|
||||||
itemTitleBuilder: (_, value) => Text(value.id.isEmpty ? S.of(context).none : value.name),
|
itemTitleBuilder: (_, value) => Text(value.id.isEmpty ? S.of(context).none : value.name),
|
||||||
onChanged: EquipmentProfileProvider.of(context).setProfile,
|
onChanged: EquipmentProfileProvider.of(context).setProfile,
|
||||||
closedChild: ReadingValueContainer.singleValue(
|
closedChild: ReadingValueContainer.singleValue(
|
||||||
value: ReadingValue(
|
value: ReadingValue(
|
||||||
label: S.of(context).equipmentProfile,
|
label: S.of(context).equipmentProfile,
|
||||||
value: EquipmentProfiles.selectedOf(context).id.isEmpty
|
value: context.listen<EquipmentProfile>().id.isEmpty
|
||||||
? S.of(context).none
|
? S.of(context).none
|
||||||
: EquipmentProfiles.selectedOf(context).name,
|
: context.listen<EquipmentProfile>().name,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/interactors/metering_interactor.dart';
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
|
import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
|
||||||
import 'package:lightmeter/screens/metering/screen_metering.dart';
|
import 'package:lightmeter/screens/metering/screen_metering.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class MeteringFlow extends StatefulWidget {
|
class MeteringFlow extends StatefulWidget {
|
||||||
const MeteringFlow({super.key});
|
const MeteringFlow({super.key});
|
||||||
|
@ -17,45 +18,31 @@ class MeteringFlow extends StatefulWidget {
|
||||||
class _MeteringFlowState extends State<MeteringFlow> {
|
class _MeteringFlowState extends State<MeteringFlow> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MeteringInteractorProvider(
|
return InheritedWidgetBase<MeteringInteractor>(
|
||||||
data: MeteringInteractor(
|
data: MeteringInteractor(
|
||||||
ServicesProvider.of(context).userPreferencesService,
|
ServiceProviders.userPreferencesServiceOf(context),
|
||||||
ServicesProvider.of(context).caffeineService,
|
ServiceProviders.caffeineServiceOf(context),
|
||||||
ServicesProvider.of(context).hapticsService,
|
ServiceProviders.hapticsServiceOf(context),
|
||||||
ServicesProvider.of(context).permissionsService,
|
ServiceProviders.permissionsServiceOf(context),
|
||||||
ServicesProvider.of(context).lightSensorService,
|
ServiceProviders.lightSensorServiceOf(context),
|
||||||
ServicesProvider.of(context).volumeEventsService,
|
ServiceProviders.volumeEventsServiceOf(context),
|
||||||
)..initialize(),
|
)..initialize(),
|
||||||
|
child: InheritedWidgetBase<VolumeKeysNotifier>(
|
||||||
|
data: VolumeKeysNotifier(ServiceProviders.volumeEventsServiceOf(context)),
|
||||||
child: MultiBlocProvider(
|
child: MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(create: (_) => MeteringCommunicationBloc()),
|
BlocProvider(create: (_) => MeteringCommunicationBloc()),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => MeteringBloc(
|
create: (context) => MeteringBloc(
|
||||||
MeteringInteractorProvider.of(context),
|
context.get<MeteringInteractor>(),
|
||||||
VolumeKeysNotifier(ServicesProvider.of(context).volumeEventsService),
|
context.get<VolumeKeysNotifier>(),
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: const MeteringScreen(),
|
child: const MeteringScreen(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MeteringInteractorProvider extends InheritedWidget {
|
|
||||||
final MeteringInteractor data;
|
|
||||||
|
|
||||||
const MeteringInteractorProvider({
|
|
||||||
required this.data,
|
|
||||||
required super.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
static MeteringInteractor of(BuildContext context) {
|
|
||||||
return context.findAncestorWidgetOfExactType<MeteringInteractorProvider>()!.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(MeteringInteractorProvider oldWidget) => false;
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,17 +6,15 @@ import 'package:lightmeter/data/models/ev_source_type.dart';
|
||||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||||
import 'package:lightmeter/data/models/film.dart';
|
import 'package:lightmeter/data/models/film.dart';
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
|
||||||
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/bottom_controls/provider_bottom_controls.dart';
|
import 'package:lightmeter/screens/metering/components/bottom_controls/provider_bottom_controls.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/camera_container/provider_container_camera.dart';
|
import 'package:lightmeter/screens/metering/components/camera_container/provider_container_camera.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart';
|
import 'package:lightmeter/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart';
|
||||||
import 'package:lightmeter/screens/metering/event_metering.dart';
|
import 'package:lightmeter/screens/metering/event_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/state_metering.dart';
|
import 'package:lightmeter/screens/metering/state_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/utils/listener_metering_layout_feature.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:lightmeter/screens/metering/utils/listsner_equipment_profiles.dart';
|
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class MeteringScreen extends StatelessWidget {
|
class MeteringScreen extends StatelessWidget {
|
||||||
|
@ -47,8 +45,8 @@ class MeteringScreen extends StatelessWidget {
|
||||||
builder: (context, state) => MeteringBottomControlsProvider(
|
builder: (context, state) => MeteringBottomControlsProvider(
|
||||||
ev: state is MeteringDataState ? state.ev : null,
|
ev: state is MeteringDataState ? state.ev : null,
|
||||||
isMetering: state.isMetering,
|
isMetering: state.isMetering,
|
||||||
onSwitchEvSourceType: ServicesProvider.of(context).environment.hasLightSensor
|
onSwitchEvSourceType: ServiceProviders.environmentOf(context).hasLightSensor
|
||||||
? UserPreferencesProvider.of(context).toggleEvSourceType
|
? EnumProviders.of(context).toggleEvSourceType
|
||||||
: null,
|
: null,
|
||||||
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
||||||
onSettings: () {
|
onSettings: () {
|
||||||
|
@ -73,12 +71,12 @@ class _InheritedListeners extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return EquipmentProfileListener(
|
return InheritedWidgetListener<EquipmentProfile>(
|
||||||
onDidChangeDependencies: (value) {
|
onDidChangeDependencies: (value) {
|
||||||
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
||||||
},
|
},
|
||||||
child: MeteringScreenLayoutFeatureListener(
|
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
||||||
feature: MeteringScreenLayoutFeature.filmPicker,
|
aspect: MeteringScreenLayoutFeature.filmPicker,
|
||||||
onDidChangeDependencies: (value) {
|
onDidChangeDependencies: (value) {
|
||||||
if (!value) context.read<MeteringBloc>().add(const FilmChangedEvent(Film.other()));
|
if (!value) context.read<MeteringBloc>().add(const FilmChangedEvent(Film.other()));
|
||||||
},
|
},
|
||||||
|
@ -113,7 +111,7 @@ class _MeteringContainerBuidler extends StatelessWidget {
|
||||||
final fastest = exposurePairs.isNotEmpty ? exposurePairs.first : null;
|
final fastest = exposurePairs.isNotEmpty ? exposurePairs.first : null;
|
||||||
final slowest = exposurePairs.isNotEmpty ? exposurePairs.last : null;
|
final slowest = exposurePairs.isNotEmpty ? exposurePairs.last : null;
|
||||||
// Doubled build here when switching evSourceType. As new source bloc fires a new state on init
|
// Doubled build here when switching evSourceType. As new source bloc fires a new state on init
|
||||||
return UserPreferencesProvider.evSourceTypeOf(context) == EvSourceType.camera
|
return EnumProviders.evSourceTypeOf(context) == EvSourceType.camera
|
||||||
? CameraContainerProvider(
|
? CameraContainerProvider(
|
||||||
fastest: fastest,
|
fastest: fastest,
|
||||||
slowest: slowest,
|
slowest: slowest,
|
||||||
|
@ -144,10 +142,10 @@ class _MeteringContainerBuidler extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Depending on the `stopType` the exposure pairs list length is multiplied by 1,2 or 3
|
/// Depending on the `stopType` the exposure pairs list length is multiplied by 1,2 or 3
|
||||||
final StopType stopType = UserPreferencesProvider.stopTypeOf(context);
|
final StopType stopType = EnumProviders.stopTypeOf(context);
|
||||||
final int evSteps = (ev * (stopType.index + 1)).round();
|
final int evSteps = (ev * (stopType.index + 1)).round();
|
||||||
|
|
||||||
final EquipmentProfile equipmentProfile = EquipmentProfiles.selectedOf(context);
|
final EquipmentProfile equipmentProfile = context.listen<EquipmentProfile>();
|
||||||
final List<ApertureValue> apertureValues =
|
final List<ApertureValue> apertureValues =
|
||||||
equipmentProfile.apertureValues.whereStopType(stopType);
|
equipmentProfile.apertureValues.whereStopType(stopType);
|
||||||
final List<ShutterSpeedValue> shutterSpeedValues =
|
final List<ShutterSpeedValue> shutterSpeedValues =
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
|
||||||
|
|
||||||
/// Listening to multiple dependencies at the same time causes firing an event for all dependencies
|
|
||||||
/// even though some of them didn't change:
|
|
||||||
/// ```dart
|
|
||||||
/// @override
|
|
||||||
/// void didChangeDependencies() {
|
|
||||||
/// super.didChangeDependencies();
|
|
||||||
/// _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
|
|
||||||
/// if (!MeteringScreenLayout.featureStatusOf(context, MeteringScreenLayoutFeature.filmPicker)) {
|
|
||||||
/// _bloc.add(const FilmChangedEvent(Film.other()));
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
/// To overcome this issue I've decided to create a generic listener,
|
|
||||||
/// that will listen to each dependency separately.
|
|
||||||
class MeteringScreenLayoutFeatureListener extends StatefulWidget {
|
|
||||||
final MeteringScreenLayoutFeature feature;
|
|
||||||
final ValueChanged<bool> onDidChangeDependencies;
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const MeteringScreenLayoutFeatureListener({
|
|
||||||
required this.feature,
|
|
||||||
required this.onDidChangeDependencies,
|
|
||||||
required this.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MeteringScreenLayoutFeatureListener> createState() =>
|
|
||||||
_MeteringScreenLayoutFeatureListenerState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MeteringScreenLayoutFeatureListenerState extends State<MeteringScreenLayoutFeatureListener> {
|
|
||||||
@override
|
|
||||||
void didChangeDependencies() {
|
|
||||||
super.didChangeDependencies();
|
|
||||||
widget.onDidChangeDependencies(
|
|
||||||
UserPreferencesProvider.meteringScreenFeatureOf(
|
|
||||||
context,
|
|
||||||
widget.feature,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return widget.child;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
||||||
|
|
||||||
class EquipmentProfileListener extends StatefulWidget {
|
|
||||||
final ValueChanged<EquipmentProfile> onDidChangeDependencies;
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const EquipmentProfileListener({
|
|
||||||
required this.onDidChangeDependencies,
|
|
||||||
required this.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<EquipmentProfileListener> createState() => _EquipmentProfileListenerState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _EquipmentProfileListenerState extends State<EquipmentProfileListener> {
|
|
||||||
@override
|
|
||||||
void didChangeDependencies() {
|
|
||||||
super.didChangeDependencies();
|
|
||||||
widget.onDidChangeDependencies(EquipmentProfiles.selectedOf(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return widget.child;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class ReportIssueListTile extends StatelessWidget {
|
class ReportIssueListTile extends StatelessWidget {
|
||||||
|
@ -13,7 +13,7 @@ class ReportIssueListTile extends StatelessWidget {
|
||||||
title: Text(S.of(context).reportIssue),
|
title: Text(S.of(context).reportIssue),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(
|
launchUrl(
|
||||||
Uri.parse(ServicesProvider.of(context).environment.issuesReportUrl),
|
Uri.parse(ServiceProviders.environmentOf(context).issuesReportUrl),
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class SourceCodeListTile extends StatelessWidget {
|
class SourceCodeListTile extends StatelessWidget {
|
||||||
|
@ -13,7 +13,7 @@ class SourceCodeListTile extends StatelessWidget {
|
||||||
title: Text(S.of(context).sourceCode),
|
title: Text(S.of(context).sourceCode),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(
|
launchUrl(
|
||||||
Uri.parse(ServicesProvider.of(context).environment.sourceCodeUrl),
|
Uri.parse(ServiceProviders.environmentOf(context).sourceCodeUrl),
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:clipboard/clipboard.dart';
|
import 'package:clipboard/clipboard.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class WriteEmailListTile extends StatelessWidget {
|
class WriteEmailListTile extends StatelessWidget {
|
||||||
|
@ -13,7 +13,7 @@ class WriteEmailListTile extends StatelessWidget {
|
||||||
leading: const Icon(Icons.email),
|
leading: const Icon(Icons.email),
|
||||||
title: Text(S.of(context).writeEmail),
|
title: Text(S.of(context).writeEmail),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final email = ServicesProvider.of(context).environment.contactEmail;
|
final email = ServiceProviders.environmentOf(context).contactEmail;
|
||||||
final mailToUrl = Uri.parse('mailto:$email?subject=M3 Lightmeter');
|
final mailToUrl = Uri.parse('mailto:$email?subject=M3 Lightmeter');
|
||||||
canLaunchUrl(mailToUrl).then((canLaunch) {
|
canLaunchUrl(mailToUrl).then((canLaunch) {
|
||||||
if (canLaunch) {
|
if (canLaunch) {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
|
|
||||||
import 'package:lightmeter/screens/settings/components/general/components/caffeine/bloc_list_tile_caffeine.dart';
|
import 'package:lightmeter/screens/settings/components/general/components/caffeine/bloc_list_tile_caffeine.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/general/components/caffeine/widget_list_tile_caffeine.dart';
|
import 'package:lightmeter/screens/settings/components/general/components/caffeine/widget_list_tile_caffeine.dart';
|
||||||
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class CaffeineListTileProvider extends StatelessWidget {
|
class CaffeineListTileProvider extends StatelessWidget {
|
||||||
const CaffeineListTileProvider({super.key});
|
const CaffeineListTileProvider({super.key});
|
||||||
|
@ -11,7 +12,7 @@ class CaffeineListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CaffeineListTileBloc(SettingsInteractorProvider.of(context)),
|
create: (context) => CaffeineListTileBloc(context.get<SettingsInteractor>()),
|
||||||
child: const CaffeineListTile(),
|
child: const CaffeineListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
|
|
||||||
import 'package:lightmeter/screens/settings/components/general/components/haptics/bloc_list_tile_haptics.dart';
|
import 'package:lightmeter/screens/settings/components/general/components/haptics/bloc_list_tile_haptics.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/general/components/haptics/widget_list_tile_haptics.dart';
|
import 'package:lightmeter/screens/settings/components/general/components/haptics/widget_list_tile_haptics.dart';
|
||||||
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class HapticsListTileProvider extends StatelessWidget {
|
class HapticsListTileProvider extends StatelessWidget {
|
||||||
const HapticsListTileProvider({super.key});
|
const HapticsListTileProvider({super.key});
|
||||||
|
@ -11,7 +12,7 @@ class HapticsListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => HapticsListTileBloc(SettingsInteractorProvider.of(context)),
|
create: (context) => HapticsListTileBloc(context.get<SettingsInteractor>()),
|
||||||
child: const HapticsListTile(),
|
child: const HapticsListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
import 'package:lightmeter/data/models/supported_locale.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart';
|
import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart';
|
||||||
|
|
||||||
class LanguageListTile extends StatelessWidget {
|
class LanguageListTile extends StatelessWidget {
|
||||||
|
@ -12,20 +12,20 @@ class LanguageListTile extends StatelessWidget {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: const Icon(Icons.language),
|
leading: const Icon(Icons.language),
|
||||||
title: Text(S.of(context).language),
|
title: Text(S.of(context).language),
|
||||||
trailing: Text(UserPreferencesProvider.localeOf(context).localizedName),
|
trailing: Text(EnumProviders.localeOf(context).localizedName),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showDialog<SupportedLocale>(
|
showDialog<SupportedLocale>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => DialogPicker<SupportedLocale>(
|
builder: (_) => DialogPicker<SupportedLocale>(
|
||||||
icon: Icons.language,
|
icon: Icons.language,
|
||||||
title: S.of(context).chooseLanguage,
|
title: S.of(context).chooseLanguage,
|
||||||
selectedValue: UserPreferencesProvider.localeOf(context),
|
selectedValue: EnumProviders.localeOf(context),
|
||||||
values: SupportedLocale.values,
|
values: SupportedLocale.values,
|
||||||
titleAdapter: (context, value) => value.localizedName,
|
titleAdapter: (context, value) => value.localizedName,
|
||||||
),
|
),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
UserPreferencesProvider.of(context).setLocale(value);
|
EnumProviders.of(context).setLocale(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
|
|
||||||
import 'package:lightmeter/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart';
|
import 'package:lightmeter/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart';
|
import 'package:lightmeter/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart';
|
||||||
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class VolumeActionsListTileProvider extends StatelessWidget {
|
class VolumeActionsListTileProvider extends StatelessWidget {
|
||||||
const VolumeActionsListTileProvider({super.key});
|
const VolumeActionsListTileProvider({super.key});
|
||||||
|
@ -11,7 +12,7 @@ class VolumeActionsListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => VolumeActionsListTileBloc(SettingsInteractorProvider.of(context)),
|
create: (context) => VolumeActionsListTileBloc(context.get<SettingsInteractor>()),
|
||||||
child: const VolumeActionsListTile(),
|
child: const VolumeActionsListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
|
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/bloc_dialog_calibration.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/bloc_dialog_calibration.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/widget_dialog_calibration.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/widget_dialog_calibration.dart';
|
||||||
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class CalibrationDialogProvider extends StatelessWidget {
|
class CalibrationDialogProvider extends StatelessWidget {
|
||||||
const CalibrationDialogProvider({super.key});
|
const CalibrationDialogProvider({super.key});
|
||||||
|
@ -11,7 +12,7 @@ class CalibrationDialogProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CalibrationDialogBloc(SettingsInteractorProvider.of(context)),
|
create: (context) => CalibrationDialogBloc(context.get<SettingsInteractor>()),
|
||||||
child: const CalibrationDialog(),
|
child: const CalibrationDialog(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/bloc_dialog_calibration.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/bloc_dialog_calibration.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/event_dialog_calibration.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/event_dialog_calibration.dart';
|
||||||
|
@ -14,7 +14,7 @@ class CalibrationDialog extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final bool hasLightSensor = ServicesProvider.of(context).environment.hasLightSensor;
|
final bool hasLightSensor = ServiceProviders.environmentOf(context).hasLightSensor;
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
icon: const Icon(Icons.settings_brightness),
|
icon: const Icon(Icons.settings_brightness),
|
||||||
titlePadding: Dimens.dialogIconTitlePadding,
|
titlePadding: Dimens.dialogIconTitlePadding,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/provider_dialog_calibration.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/provider_dialog_calibration.dart';
|
||||||
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class CalibrationListTile extends StatelessWidget {
|
class CalibrationListTile extends StatelessWidget {
|
||||||
const CalibrationListTile({super.key});
|
const CalibrationListTile({super.key});
|
||||||
|
@ -14,8 +15,8 @@ class CalibrationListTile extends StatelessWidget {
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showDialog<double>(
|
showDialog<double>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => SettingsInteractorProvider(
|
builder: (_) => InheritedWidgetBase(
|
||||||
data: SettingsInteractorProvider.of(context),
|
data: context.get<SettingsInteractor>(),
|
||||||
child: const CalibrationDialogProvider(),
|
child: const CalibrationDialogProvider(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
|
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/widget_container_equipment_profile.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/widget_container_equipment_profile.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart';
|
||||||
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class EquipmentProfilesScreen extends StatefulWidget {
|
class EquipmentProfilesScreen extends StatefulWidget {
|
||||||
|
@ -19,12 +19,13 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
static const maxProfiles = 5 + 1; // replace with a constant from iap
|
static const maxProfiles = 5 + 1; // replace with a constant from iap
|
||||||
|
|
||||||
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
|
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
|
||||||
int get profilesCount => EquipmentProfiles.of(context).length;
|
int get profilesCount => context.listen<EquipmentProfiles>().length;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void initState() {
|
||||||
super.didChangeDependencies();
|
super.initState();
|
||||||
profileContainersKeys = EquipmentProfiles.of(context)
|
profileContainersKeys = context
|
||||||
|
.get<EquipmentProfiles>()
|
||||||
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
|
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
@ -57,14 +58,14 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
),
|
),
|
||||||
child: EquipmentProfileContainer(
|
child: EquipmentProfileContainer(
|
||||||
key: profileContainersKeys[index],
|
key: profileContainersKeys[index],
|
||||||
data: EquipmentProfiles.of(context)[index],
|
data: context.listen<EquipmentProfiles>()[index],
|
||||||
onExpand: () => _keepExpandedAt(index),
|
onExpand: () => _keepExpandedAt(index),
|
||||||
onUpdate: (profileData) => _updateProfileAt(profileData, index),
|
onUpdate: (profileData) => _updateProfileAt(profileData, index),
|
||||||
onDelete: () => _removeProfileAt(index),
|
onDelete: () => _removeProfileAt(index),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: const SizedBox.shrink(),
|
: const SizedBox.shrink(),
|
||||||
childCount: profilesCount,
|
childCount: profileContainersKeys.length,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -78,6 +79,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
EquipmentProfileProvider.of(context).addProfile(value);
|
EquipmentProfileProvider.of(context).addProfile(value);
|
||||||
|
profileContainersKeys.add(GlobalKey<EquipmentProfileContainerState>());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -87,7 +89,8 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _removeProfileAt(int index) {
|
void _removeProfileAt(int index) {
|
||||||
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]);
|
EquipmentProfileProvider.of(context).deleteProfile(context.listen<EquipmentProfiles>()[index]);
|
||||||
|
profileContainersKeys.removeAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _keepExpandedAt(int index) {
|
void _keepExpandedAt(int index) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart';
|
import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
|
@ -12,20 +12,20 @@ class StopTypeListTile extends StatelessWidget {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: const Icon(Icons.straighten),
|
leading: const Icon(Icons.straighten),
|
||||||
title: Text(S.of(context).fractionalStops),
|
title: Text(S.of(context).fractionalStops),
|
||||||
trailing: Text(_typeToString(context, UserPreferencesProvider.stopTypeOf(context))),
|
trailing: Text(_typeToString(context, EnumProviders.stopTypeOf(context))),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showDialog<StopType>(
|
showDialog<StopType>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => DialogPicker<StopType>(
|
builder: (_) => DialogPicker<StopType>(
|
||||||
icon: Icons.straighten,
|
icon: Icons.straighten,
|
||||||
title: S.of(context).showFractionalStops,
|
title: S.of(context).showFractionalStops,
|
||||||
selectedValue: UserPreferencesProvider.stopTypeOf(context),
|
selectedValue: EnumProviders.stopTypeOf(context),
|
||||||
values: StopType.values,
|
values: StopType.values,
|
||||||
titleAdapter: _typeToString,
|
titleAdapter: _typeToString,
|
||||||
),
|
),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
UserPreferencesProvider.of(context).setStopType(value);
|
EnumProviders.of(context).setStopType(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
|
||||||
class MeteringScreenLayoutFeaturesDialog extends StatefulWidget {
|
class MeteringScreenLayoutFeaturesDialog extends StatefulWidget {
|
||||||
|
@ -14,7 +14,7 @@ class MeteringScreenLayoutFeaturesDialog extends StatefulWidget {
|
||||||
|
|
||||||
class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayoutFeaturesDialog> {
|
class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayoutFeaturesDialog> {
|
||||||
late final _features =
|
late final _features =
|
||||||
MeteringScreenLayoutConfig.from(UserPreferencesProvider.meteringScreenConfigOf(context));
|
MeteringScreenLayoutConfig.from(MeteringScreenLayout.of(context, listen: false));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -56,7 +56,7 @@ class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayou
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
UserPreferencesProvider.of(context).setMeteringScreenLayout(_features);
|
MeteringScreenLayoutProvider.of(context).updateFeatures(_features);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Text(S.of(context).save),
|
child: Text(S.of(context).save),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
|
||||||
class DynamicColorListTile extends StatelessWidget {
|
class DynamicColorListTile extends StatelessWidget {
|
||||||
|
@ -12,8 +12,8 @@ class DynamicColorListTile extends StatelessWidget {
|
||||||
return SwitchListTile(
|
return SwitchListTile(
|
||||||
secondary: const Icon(Icons.colorize),
|
secondary: const Icon(Icons.colorize),
|
||||||
title: Text(S.of(context).dynamicColor),
|
title: Text(S.of(context).dynamicColor),
|
||||||
value: UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled,
|
value: EnumProviders.dynamicColorStateOf(context) == DynamicColorState.enabled,
|
||||||
onChanged: UserPreferencesProvider.of(context).enableDynamicColor,
|
onChanged: EnumProviders.of(context).enableDynamicColor,
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart';
|
import 'package:lightmeter/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart';
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ class PrimaryColorListTile extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled) {
|
if (EnumProviders.dynamicColorStateOf(context) == DynamicColorState.enabled) {
|
||||||
return Opacity(
|
return Opacity(
|
||||||
opacity: Dimens.disabledOpacity,
|
opacity: Dimens.disabledOpacity,
|
||||||
child: IgnorePointer(
|
child: IgnorePointer(
|
||||||
|
@ -30,7 +30,7 @@ class PrimaryColorListTile extends StatelessWidget {
|
||||||
builder: (_) => const PrimaryColorDialogPicker(),
|
builder: (_) => const PrimaryColorDialogPicker(),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
UserPreferencesProvider.of(context).setPrimaryColor(value);
|
EnumProviders.of(context).setPrimaryColor(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/theme_type.dart';
|
import 'package:lightmeter/data/models/theme_type.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart';
|
import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart';
|
||||||
|
|
||||||
class ThemeTypeListTile extends StatelessWidget {
|
class ThemeTypeListTile extends StatelessWidget {
|
||||||
|
@ -12,20 +12,20 @@ class ThemeTypeListTile extends StatelessWidget {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: const Icon(Icons.brightness_6),
|
leading: const Icon(Icons.brightness_6),
|
||||||
title: Text(S.of(context).theme),
|
title: Text(S.of(context).theme),
|
||||||
trailing: Text(_typeToString(context, UserPreferencesProvider.themeTypeOf(context))),
|
trailing: Text(_typeToString(context, EnumProviders.themeTypeOf(context))),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showDialog<ThemeType>(
|
showDialog<ThemeType>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => DialogPicker<ThemeType>(
|
builder: (_) => DialogPicker<ThemeType>(
|
||||||
icon: Icons.brightness_6,
|
icon: Icons.brightness_6,
|
||||||
title: S.of(context).chooseTheme,
|
title: S.of(context).chooseTheme,
|
||||||
selectedValue: UserPreferencesProvider.themeTypeOf(context),
|
selectedValue: EnumProviders.themeTypeOf(context),
|
||||||
values: ThemeType.values,
|
values: ThemeType.values,
|
||||||
titleAdapter: _typeToString,
|
titleAdapter: _typeToString,
|
||||||
),
|
),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
UserPreferencesProvider.of(context).setThemeType(value);
|
EnumProviders.of(context).setThemeType(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/enum_providers.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/shared/settings_section/widget_settings_section.dart';
|
import 'package:lightmeter/screens/settings/components/shared/settings_section/widget_settings_section.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart';
|
import 'package:lightmeter/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart';
|
import 'package:lightmeter/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart';
|
||||||
|
@ -17,7 +17,7 @@ class ThemeSettingsSection extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
const ThemeTypeListTile(),
|
const ThemeTypeListTile(),
|
||||||
const PrimaryColorListTile(),
|
const PrimaryColorListTile(),
|
||||||
if (UserPreferencesProvider.dynamicColorStateOf(context) != DynamicColorState.unavailable)
|
if (EnumProviders.dynamicColorStateOf(context) != DynamicColorState.unavailable)
|
||||||
const DynamicColorListTile(),
|
const DynamicColorListTile(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,38 +1,22 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/interactors/settings_interactor.dart';
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/service_providers.dart';
|
||||||
import 'package:lightmeter/screens/settings/screen_settings.dart';
|
import 'package:lightmeter/screens/settings/screen_settings.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class SettingsFlow extends StatelessWidget {
|
class SettingsFlow extends StatelessWidget {
|
||||||
const SettingsFlow({super.key});
|
const SettingsFlow({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SettingsInteractorProvider(
|
return InheritedWidgetBase<SettingsInteractor>(
|
||||||
data: SettingsInteractor(
|
data: SettingsInteractor(
|
||||||
ServicesProvider.of(context).userPreferencesService,
|
ServiceProviders.userPreferencesServiceOf(context),
|
||||||
ServicesProvider.of(context).caffeineService,
|
ServiceProviders.caffeineServiceOf(context),
|
||||||
ServicesProvider.of(context).hapticsService,
|
ServiceProviders.hapticsServiceOf(context),
|
||||||
ServicesProvider.of(context).volumeEventsService,
|
ServiceProviders.volumeEventsServiceOf(context),
|
||||||
),
|
),
|
||||||
child: const SettingsScreen(),
|
child: const SettingsScreen(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsInteractorProvider extends InheritedWidget {
|
|
||||||
final SettingsInteractor data;
|
|
||||||
|
|
||||||
const SettingsInteractorProvider({
|
|
||||||
required this.data,
|
|
||||||
required super.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
static SettingsInteractor of(BuildContext context) {
|
|
||||||
return context.findAncestorWidgetOfExactType<SettingsInteractorProvider>()!.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(SettingsInteractorProvider oldWidget) => false;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/about/widget_settings_section_about.dart';
|
import 'package:lightmeter/screens/settings/components/about/widget_settings_section_about.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/general/widget_settings_section_general.dart';
|
import 'package:lightmeter/screens/settings/components/general/widget_settings_section_general.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/widget_settings_section_metering.dart';
|
import 'package:lightmeter/screens/settings/components/metering/widget_settings_section_metering.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/theme/widget_settings_section_theme.dart';
|
import 'package:lightmeter/screens/settings/components/theme/widget_settings_section_theme.dart';
|
||||||
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
|
||||||
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class SettingsScreen extends StatefulWidget {
|
class SettingsScreen extends StatefulWidget {
|
||||||
const SettingsScreen({super.key});
|
const SettingsScreen({super.key});
|
||||||
|
@ -18,12 +19,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
SettingsInteractorProvider.of(context).disableVolumeHandling();
|
context.get<SettingsInteractor>().disableVolumeHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void deactivate() {
|
void deactivate() {
|
||||||
SettingsInteractorProvider.of(context).restoreVolumeHandling();
|
context.get<SettingsInteractor>().restoreVolumeHandling();
|
||||||
super.deactivate();
|
super.deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
171
lib/utils/inherited_generics.dart
Normal file
171
lib/utils/inherited_generics.dart
Normal file
|
@ -0,0 +1,171 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
/// Listening to multiple dependencies at the same time causes firing an event for all dependencies
|
||||||
|
/// even though some of them didn't change:
|
||||||
|
/// ```dart
|
||||||
|
/// @override
|
||||||
|
/// void didChangeDependencies() {
|
||||||
|
/// super.didChangeDependencies();
|
||||||
|
/// _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
|
||||||
|
/// if (!MeteringScreenLayout.featureStatusOf(context, MeteringScreenLayoutFeature.filmPicker)) {
|
||||||
|
/// _bloc.add(const FilmChangedEvent(Film.other()));
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
/// To overcome this issue I've decided to create a generic listener,
|
||||||
|
/// that will listen to each dependency separately.
|
||||||
|
class InheritedWidgetListener<T> extends StatefulWidget {
|
||||||
|
final ValueChanged<T> onDidChangeDependencies;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const InheritedWidgetListener({
|
||||||
|
required this.onDidChangeDependencies,
|
||||||
|
required this.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<InheritedWidgetListener<T>> createState() => _InheritedWidgetListenerState<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InheritedWidgetListenerState<T> extends State<InheritedWidgetListener<T>> {
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
widget.onDidChangeDependencies(context.listen<T>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return widget.child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritedWidgetBase<T> extends InheritedWidget {
|
||||||
|
final T data;
|
||||||
|
|
||||||
|
const InheritedWidgetBase({
|
||||||
|
required this.data,
|
||||||
|
required super.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static T of<T>(BuildContext context, {bool listen = true}) {
|
||||||
|
if (listen) {
|
||||||
|
return context.dependOnInheritedWidgetOfExactType<InheritedWidgetBase<T>>()!.data;
|
||||||
|
} else {
|
||||||
|
return context.findAncestorWidgetOfExactType<InheritedWidgetBase<T>>()!.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(InheritedWidgetBase<T> oldWidget) => true;
|
||||||
|
}
|
||||||
|
|
||||||
|
extension InheritedWidgetBaseContext on BuildContext {
|
||||||
|
T get<T>() {
|
||||||
|
return InheritedWidgetBase.of<T>(this, listen: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
T listen<T>() {
|
||||||
|
return InheritedWidgetBase.of<T>(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Listening to multiple dependencies at the same time causes firing an event for all dependencies
|
||||||
|
/// even though some of them didn't change:
|
||||||
|
/// ```dart
|
||||||
|
/// @override
|
||||||
|
/// void didChangeDependencies() {
|
||||||
|
/// super.didChangeDependencies();
|
||||||
|
/// _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
|
||||||
|
/// if (!MeteringScreenLayout.featureStatusOf(context, MeteringScreenLayoutFeature.filmPicker)) {
|
||||||
|
/// _bloc.add(const FilmChangedEvent(Film.other()));
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
/// To overcome this issue I've decided to create a generic listener,
|
||||||
|
/// that will listen to each dependency separately.
|
||||||
|
class InheritedModelAspectListener<A extends Object, T> extends StatefulWidget {
|
||||||
|
final A aspect;
|
||||||
|
final ValueChanged<T> onDidChangeDependencies;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const InheritedModelAspectListener({
|
||||||
|
required this.aspect,
|
||||||
|
required this.onDidChangeDependencies,
|
||||||
|
required this.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<InheritedModelAspectListener<A, T>> createState() =>
|
||||||
|
_InheritedModelAspectListenerState<A, T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InheritedModelAspectListenerState<A extends Object, T>
|
||||||
|
extends State<InheritedModelAspectListener<A, T>> {
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
widget.onDidChangeDependencies(context.listenModelFeature<A, T>(widget.aspect));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return widget.child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritedModelBase<A, T> extends InheritedModel<A> {
|
||||||
|
final Map<A, T> data;
|
||||||
|
|
||||||
|
const InheritedModelBase({
|
||||||
|
required this.data,
|
||||||
|
required super.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static Map<A, T> of<A, T>(BuildContext context, {bool listen = true}) {
|
||||||
|
if (listen) {
|
||||||
|
return context.dependOnInheritedWidgetOfExactType<InheritedModelBase<A, T>>()!.data;
|
||||||
|
} else {
|
||||||
|
return context.findAncestorWidgetOfExactType<InheritedModelBase<A, T>>()!.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static T featureOf<A extends Object, T>(BuildContext context, A aspect) {
|
||||||
|
return InheritedModel.inheritFrom<InheritedModelBase<A, T>>(context, aspect: aspect)!
|
||||||
|
.data[aspect]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(InheritedModelBase oldWidget) => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotifyDependent(
|
||||||
|
InheritedModelBase<A, T> oldWidget,
|
||||||
|
Set<A> dependencies,
|
||||||
|
) {
|
||||||
|
for (final dependecy in dependencies) {
|
||||||
|
if (oldWidget.data[dependecy] != data[dependecy]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension InheritedModelBaseContext on BuildContext {
|
||||||
|
Map<A, T> getModel<A, T>() {
|
||||||
|
return InheritedModelBase.of<A, T>(this, listen: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<A, T> listenModel<A, T>() {
|
||||||
|
return InheritedModelBase.of<A, T>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
T listenModelFeature<A extends Object, T>(A aspect) {
|
||||||
|
return InheritedModelBase.featureOf<A, T>(this, aspect);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue