mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 00:10:47 +00:00
ML-105 Hide providers from the widget tree (#106)
* Added `ServiceProviders` widget * Added `EnumProviders` widget for enum values * Moved `ThemeProvider` functionality to `EnumProviders` * Style * `EnumProviders` -> `UserPreferencesProvider` * `ServiceProviders` -> `ServiceProvider` * Moved `MeteringScreenLayoutProvider` functionality to `UserPreferencesProvider` * typo * Removed `InheritedModelAspectListener` * TODO * Removed Inherited Generics * Removed redundant `LightmeterProviders` * Removed redundant methods from `ServicesProvider` * `_inheritFrom` -> `_inheritFromEnumsModel` * Fixed `MeteringScreenLayoutConfig` updates * Separated `_ThemeModel` * typo * `_EnumsModel` -> `_UserPreferencesModel`
This commit is contained in:
parent
4917ee8aef
commit
5adcee00dd
43 changed files with 790 additions and 937 deletions
|
@ -1,13 +1,22 @@
|
||||||
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.dart';
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
|
import 'package:lightmeter/providers/user_preferences_provider.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:lightmeter/utils/inherited_generics.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;
|
||||||
|
@ -16,56 +25,71 @@ class Application extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return LightmeterProviders(
|
return FutureBuilder(
|
||||||
env: env,
|
future: Future.wait([
|
||||||
builder: (context, ready) => ready
|
SharedPreferences.getInstance(),
|
||||||
? _AnnotatedRegionWrapper(
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
||||||
child: MaterialApp(
|
]),
|
||||||
theme: context.listen<ThemeData>(),
|
builder: (_, snapshot) {
|
||||||
locale: Locale(context.listen<SupportedLocale>().intlName),
|
if (snapshot.data != null) {
|
||||||
localizationsDelegates: const [
|
return ServicesProvider(
|
||||||
S.delegate,
|
caffeineService: const CaffeineService(),
|
||||||
GlobalMaterialLocalizations.delegate,
|
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
||||||
GlobalWidgetsLocalizations.delegate,
|
hapticsService: const HapticsService(),
|
||||||
GlobalCupertinoLocalizations.delegate,
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
||||||
],
|
permissionsService: const PermissionsService(),
|
||||||
supportedLocales: S.delegate.supportedLocales,
|
userPreferencesService: UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
||||||
builder: (context, child) => MediaQuery(
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
||||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
child: UserPreferencesProvider(
|
||||||
child: child!,
|
child: EquipmentProfileProvider(
|
||||||
|
child: Builder(
|
||||||
|
builder: (context) {
|
||||||
|
final theme = UserPreferencesProvider.themeOf(context);
|
||||||
|
final systemIconsBrightness =
|
||||||
|
ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface);
|
||||||
|
return AnnotatedRegion(
|
||||||
|
value: SystemUiOverlayStyle(
|
||||||
|
statusBarColor: Colors.transparent,
|
||||||
|
statusBarBrightness: systemIconsBrightness == Brightness.light
|
||||||
|
? Brightness.dark
|
||||||
|
: Brightness.light,
|
||||||
|
statusBarIconBrightness: systemIconsBrightness,
|
||||||
|
systemNavigationBarColor: Colors.transparent,
|
||||||
|
systemNavigationBarIconBrightness: systemIconsBrightness,
|
||||||
|
),
|
||||||
|
child: MaterialApp(
|
||||||
|
theme: theme,
|
||||||
|
locale: Locale(UserPreferencesProvider.localeOf(context).intlName),
|
||||||
|
localizationsDelegates: const [
|
||||||
|
S.delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
],
|
||||||
|
supportedLocales: S.delegate.supportedLocales,
|
||||||
|
builder: (context, child) => MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||||
|
child: child!,
|
||||||
|
),
|
||||||
|
initialRoute: "metering",
|
||||||
|
routes: {
|
||||||
|
"metering": (context) => const MeteringFlow(),
|
||||||
|
"settings": (context) => const SettingsFlow(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
initialRoute: "metering",
|
|
||||||
routes: {
|
|
||||||
"metering": (context) => const MeteringFlow(),
|
|
||||||
"settings": (context) => const SettingsFlow(),
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
: const SizedBox(),
|
);
|
||||||
);
|
} else if (snapshot.error != null) {
|
||||||
}
|
return Center(child: Text(snapshot.error!.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AnnotatedRegionWrapper extends StatelessWidget {
|
// TODO(@vodemn): maybe user splashscreen instead
|
||||||
final Widget child;
|
return const SizedBox();
|
||||||
|
},
|
||||||
const _AnnotatedRegionWrapper({required this.child});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final systemIconsBrightness = ThemeData.estimateBrightnessForColor(
|
|
||||||
context.listen<ThemeData>().colorScheme.onSurface,
|
|
||||||
);
|
|
||||||
return AnnotatedRegion(
|
|
||||||
value: SystemUiOverlayStyle(
|
|
||||||
statusBarColor: Colors.transparent,
|
|
||||||
statusBarBrightness:
|
|
||||||
systemIconsBrightness == Brightness.light ? Brightness.dark : Brightness.light,
|
|
||||||
statusBarIconBrightness: systemIconsBrightness,
|
|
||||||
systemNavigationBarColor: Colors.transparent,
|
|
||||||
systemNavigationBarIconBrightness: systemIconsBrightness,
|
|
||||||
),
|
|
||||||
child: child,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,77 +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';
|
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
|
||||||
import 'package:lightmeter/providers/ev_source_type_provider.dart';
|
|
||||||
import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
|
||||||
import 'package:lightmeter/providers/stop_type_provider.dart';
|
|
||||||
import 'package:lightmeter/providers/supported_locale_provider.dart';
|
|
||||||
import 'package:lightmeter/providers/theme_provider.dart';
|
|
||||||
import 'package:lightmeter/utils/inherited_generics.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 InheritedWidgetBase<Environment>(
|
|
||||||
data: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
|
||||||
child: InheritedWidgetBase<UserPreferencesService>(
|
|
||||||
data: UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
|
||||||
child: InheritedWidgetBase<LightSensorService>(
|
|
||||||
data: const LightSensorService(LocalPlatform()),
|
|
||||||
child: InheritedWidgetBase<CaffeineService>(
|
|
||||||
data: const CaffeineService(),
|
|
||||||
child: InheritedWidgetBase<HapticsService>(
|
|
||||||
data: const HapticsService(),
|
|
||||||
child: InheritedWidgetBase<VolumeEventsService>(
|
|
||||||
data: const VolumeEventsService(LocalPlatform()),
|
|
||||||
child: InheritedWidgetBase<PermissionsService>(
|
|
||||||
data: const PermissionsService(),
|
|
||||||
child: MeteringScreenLayoutProvider(
|
|
||||||
child: StopTypeProvider(
|
|
||||||
child: EquipmentProfileProvider(
|
|
||||||
child: EvSourceTypeProvider(
|
|
||||||
child: SupportedLocaleProvider(
|
|
||||||
child: ThemeProvider(
|
|
||||||
child: Builder(
|
|
||||||
builder: (context) => builder(context, true),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (snapshot.error != null) {
|
|
||||||
return Center(child: Text(snapshot.error!.toString()));
|
|
||||||
}
|
|
||||||
return builder(context, false);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,9 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
import 'package:lightmeter/providers/services_provider.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';
|
||||||
|
|
||||||
typedef EquipmentProfiles = List<EquipmentProfile>;
|
// TODO(@vodemn): This will be removed in #89
|
||||||
|
|
||||||
class EquipmentProfileProvider extends StatefulWidget {
|
class EquipmentProfileProvider extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
|
@ -35,7 +33,8 @@ 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: () {
|
||||||
context.get<UserPreferencesService>().selectedEquipmentProfileId = _defaultProfile.id;
|
ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId =
|
||||||
|
_defaultProfile.id;
|
||||||
return _defaultProfile;
|
return _defaultProfile;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -43,18 +42,16 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_selectedId = context.get<UserPreferencesService>().selectedEquipmentProfileId;
|
_selectedId = ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId;
|
||||||
_customProfiles = context.get<UserPreferencesService>().equipmentProfiles;
|
_customProfiles = ServicesProvider.of(context).userPreferencesService.equipmentProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InheritedWidgetBase<List<EquipmentProfile>>(
|
return EquipmentProfiles(
|
||||||
data: [_defaultProfile] + _customProfiles,
|
profiles: [_defaultProfile] + _customProfiles,
|
||||||
child: InheritedWidgetBase<EquipmentProfile>(
|
selected: _selectedProfile,
|
||||||
data: _selectedProfile,
|
child: widget.child,
|
||||||
child: widget.child,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +59,8 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedId = data.id;
|
_selectedId = data.id;
|
||||||
});
|
});
|
||||||
context.get<UserPreferencesService>().selectedEquipmentProfileId = _selectedProfile.id;
|
ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId =
|
||||||
|
_selectedProfile.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a default equipment profile
|
/// Creates a default equipment profile
|
||||||
|
@ -94,7 +92,48 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _refreshSavedProfiles() {
|
void _refreshSavedProfiles() {
|
||||||
context.get<UserPreferencesService>().equipmentProfiles = _customProfiles;
|
ServicesProvider.of(context).userPreferencesService.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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:lightmeter/data/models/ev_source_type.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
||||||
import 'package:lightmeter/environment.dart';
|
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class EvSourceTypeProvider extends StatefulWidget {
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const EvSourceTypeProvider({required this.child, super.key});
|
|
||||||
|
|
||||||
static EvSourceTypeProviderState of(BuildContext context) {
|
|
||||||
return context.findAncestorStateOfType<EvSourceTypeProviderState>()!;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<EvSourceTypeProvider> createState() => EvSourceTypeProviderState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class EvSourceTypeProviderState extends State<EvSourceTypeProvider> {
|
|
||||||
late final ValueNotifier<EvSourceType> valueListenable;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
final evSourceType = context.get<UserPreferencesService>().evSourceType;
|
|
||||||
valueListenable = ValueNotifier(
|
|
||||||
evSourceType == EvSourceType.sensor && !context.get<Environment>().hasLightSensor
|
|
||||||
? EvSourceType.camera
|
|
||||||
: evSourceType,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
valueListenable.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ValueListenableBuilder(
|
|
||||||
valueListenable: valueListenable,
|
|
||||||
builder: (_, value, child) => InheritedWidgetBase<EvSourceType>(
|
|
||||||
data: value,
|
|
||||||
child: child!,
|
|
||||||
),
|
|
||||||
child: widget.child,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toggleType() {
|
|
||||||
switch (valueListenable.value) {
|
|
||||||
case EvSourceType.camera:
|
|
||||||
if (context.get<Environment>().hasLightSensor) {
|
|
||||||
valueListenable.value = EvSourceType.sensor;
|
|
||||||
}
|
|
||||||
case EvSourceType.sensor:
|
|
||||||
valueListenable.value = EvSourceType.camera;
|
|
||||||
}
|
|
||||||
context.get<UserPreferencesService>().evSourceType = valueListenable.value;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.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 =
|
|
||||||
context.get<UserPreferencesService>().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,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
context.get<UserPreferencesService>().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]!;
|
|
||||||
}
|
|
||||||
}
|
|
36
lib/providers/services_provider.dart
Normal file
36
lib/providers/services_provider.dart
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
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,42 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
||||||
|
|
||||||
class StopTypeProvider extends StatefulWidget {
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const StopTypeProvider({required this.child, super.key});
|
|
||||||
|
|
||||||
static StopTypeProviderState of(BuildContext context) {
|
|
||||||
return context.findAncestorStateOfType<StopTypeProviderState>()!;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<StopTypeProvider> createState() => StopTypeProviderState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class StopTypeProviderState extends State<StopTypeProvider> {
|
|
||||||
late StopType _stopType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_stopType = context.get<UserPreferencesService>().stopType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return InheritedWidgetBase<StopType>(
|
|
||||||
data: _stopType,
|
|
||||||
child: widget.child,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set(StopType type) {
|
|
||||||
setState(() {
|
|
||||||
_stopType = type;
|
|
||||||
});
|
|
||||||
context.get<UserPreferencesService>().stopType = type;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class SupportedLocaleProvider extends StatefulWidget {
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const SupportedLocaleProvider({required this.child, super.key});
|
|
||||||
|
|
||||||
static SupportedLocaleProviderState of(BuildContext context) {
|
|
||||||
return context.findAncestorStateOfType<SupportedLocaleProviderState>()!;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<SupportedLocaleProvider> createState() => SupportedLocaleProviderState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class SupportedLocaleProviderState extends State<SupportedLocaleProvider> {
|
|
||||||
late final ValueNotifier<SupportedLocale> valueListenable;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
valueListenable = ValueNotifier(context.get<UserPreferencesService>().locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
valueListenable.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ValueListenableBuilder(
|
|
||||||
valueListenable: valueListenable,
|
|
||||||
builder: (_, value, child) => InheritedWidgetBase<SupportedLocale>(
|
|
||||||
data: value,
|
|
||||||
child: child!,
|
|
||||||
),
|
|
||||||
child: widget.child,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLocale(SupportedLocale locale) {
|
|
||||||
S.load(Locale(locale.intlName)).then((value) {
|
|
||||||
valueListenable.value = locale;
|
|
||||||
context.get<UserPreferencesService>().locale = locale;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,257 +0,0 @@
|
||||||
import 'package:dynamic_color/dynamic_color.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/scheduler.dart';
|
|
||||||
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
|
||||||
import 'package:lightmeter/data/models/theme_type.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
import 'package:material_color_utilities/material_color_utilities.dart';
|
|
||||||
|
|
||||||
class ThemeProvider extends StatefulWidget {
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const ThemeProvider({
|
|
||||||
required this.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
static ThemeProviderState of(BuildContext context) {
|
|
||||||
return context.findAncestorStateOfType<ThemeProviderState>()!;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const primaryColorsList = [
|
|
||||||
Color(0xfff44336),
|
|
||||||
Color(0xffe91e63),
|
|
||||||
Color(0xff9c27b0),
|
|
||||||
Color(0xff673ab7),
|
|
||||||
Color(0xff3f51b5),
|
|
||||||
Color(0xff2196f3),
|
|
||||||
Color(0xff03a9f4),
|
|
||||||
Color(0xff00bcd4),
|
|
||||||
Color(0xff009688),
|
|
||||||
Color(0xff4caf50),
|
|
||||||
Color(0xff8bc34a),
|
|
||||||
Color(0xffcddc39),
|
|
||||||
Color(0xffffeb3b),
|
|
||||||
Color(0xffffc107),
|
|
||||||
Color(0xffff9800),
|
|
||||||
Color(0xffff5722),
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ThemeProvider> createState() => ThemeProviderState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserver {
|
|
||||||
UserPreferencesService get _prefs => context.get<UserPreferencesService>();
|
|
||||||
|
|
||||||
late final _themeTypeNotifier = ValueNotifier<ThemeType>(_prefs.themeType);
|
|
||||||
late final _dynamicColorNotifier = ValueNotifier<bool>(_prefs.dynamicColor);
|
|
||||||
late final _primaryColorNotifier = ValueNotifier<Color>(_prefs.primaryColor);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
WidgetsBinding.instance.addObserver(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didChangePlatformBrightness() {
|
|
||||||
super.didChangePlatformBrightness();
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
WidgetsBinding.instance.removeObserver(this);
|
|
||||||
_themeTypeNotifier.dispose();
|
|
||||||
_dynamicColorNotifier.dispose();
|
|
||||||
_primaryColorNotifier.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ValueListenableBuilder(
|
|
||||||
valueListenable: _themeTypeNotifier,
|
|
||||||
builder: (_, themeType, __) => InheritedWidgetBase<ThemeType>(
|
|
||||||
data: themeType,
|
|
||||||
child: ValueListenableBuilder(
|
|
||||||
valueListenable: _dynamicColorNotifier,
|
|
||||||
builder: (_, useDynamicColor, __) => _DynamicColorProvider(
|
|
||||||
useDynamicColor: useDynamicColor,
|
|
||||||
themeBrightness: _themeBrightness,
|
|
||||||
builder: (_, dynamicPrimaryColor) => ValueListenableBuilder(
|
|
||||||
valueListenable: _primaryColorNotifier,
|
|
||||||
builder: (_, primaryColor, __) => _ThemeDataProvider(
|
|
||||||
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
|
||||||
brightness: _themeBrightness,
|
|
||||||
child: widget.child,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setThemeType(ThemeType themeType) {
|
|
||||||
_themeTypeNotifier.value = themeType;
|
|
||||||
_prefs.themeType = themeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
Brightness get _themeBrightness {
|
|
||||||
switch (_themeTypeNotifier.value) {
|
|
||||||
case ThemeType.light:
|
|
||||||
return Brightness.light;
|
|
||||||
case ThemeType.dark:
|
|
||||||
return Brightness.dark;
|
|
||||||
case ThemeType.systemDefault:
|
|
||||||
return SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPrimaryColor(Color color) {
|
|
||||||
_primaryColorNotifier.value = color;
|
|
||||||
_prefs.primaryColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void enableDynamicColor(bool enable) {
|
|
||||||
_dynamicColorNotifier.value = enable;
|
|
||||||
_prefs.dynamicColor = enable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DynamicColorProvider extends StatelessWidget {
|
|
||||||
final bool useDynamicColor;
|
|
||||||
final Brightness themeBrightness;
|
|
||||||
final Widget Function(BuildContext context, Color? primaryColor) builder;
|
|
||||||
|
|
||||||
const _DynamicColorProvider({
|
|
||||||
required this.useDynamicColor,
|
|
||||||
required this.themeBrightness,
|
|
||||||
required this.builder,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return DynamicColorBuilder(
|
|
||||||
builder: (lightDynamic, darkDynamic) {
|
|
||||||
late final DynamicColorState state;
|
|
||||||
late final Color? dynamicPrimaryColor;
|
|
||||||
if (lightDynamic != null && darkDynamic != null) {
|
|
||||||
if (useDynamicColor) {
|
|
||||||
dynamicPrimaryColor =
|
|
||||||
(themeBrightness == Brightness.light ? lightDynamic : darkDynamic).primary;
|
|
||||||
state = DynamicColorState.enabled;
|
|
||||||
} else {
|
|
||||||
dynamicPrimaryColor = null;
|
|
||||||
state = DynamicColorState.disabled;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dynamicPrimaryColor = null;
|
|
||||||
state = DynamicColorState.unavailable;
|
|
||||||
}
|
|
||||||
return InheritedWidgetBase<DynamicColorState>(
|
|
||||||
data: state,
|
|
||||||
child: builder(context, dynamicPrimaryColor),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemeDataProvider extends StatelessWidget {
|
|
||||||
final Color primaryColor;
|
|
||||||
final Brightness brightness;
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const _ThemeDataProvider({
|
|
||||||
required this.primaryColor,
|
|
||||||
required this.brightness,
|
|
||||||
required this.child,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return InheritedWidgetBase<ThemeData>(
|
|
||||||
data: _themeFromColorScheme(_colorSchemeFromColor()),
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ThemeData _themeFromColorScheme(ColorScheme scheme) {
|
|
||||||
return ThemeData(
|
|
||||||
useMaterial3: true,
|
|
||||||
brightness: scheme.brightness,
|
|
||||||
primaryColor: primaryColor,
|
|
||||||
colorScheme: scheme,
|
|
||||||
appBarTheme: AppBarTheme(
|
|
||||||
elevation: 4,
|
|
||||||
color: scheme.surface,
|
|
||||||
surfaceTintColor: scheme.surfaceTint,
|
|
||||||
),
|
|
||||||
cardTheme: CardTheme(
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
color: scheme.surface,
|
|
||||||
elevation: 4,
|
|
||||||
margin: EdgeInsets.zero,
|
|
||||||
shadowColor: Colors.transparent,
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(Dimens.borderRadiusL)),
|
|
||||||
surfaceTintColor: scheme.surfaceTint,
|
|
||||||
),
|
|
||||||
dialogBackgroundColor: scheme.surface,
|
|
||||||
dialogTheme: DialogTheme(
|
|
||||||
backgroundColor: scheme.surface,
|
|
||||||
surfaceTintColor: scheme.surfaceTint,
|
|
||||||
elevation: 6,
|
|
||||||
),
|
|
||||||
dividerColor: scheme.outlineVariant,
|
|
||||||
dividerTheme: DividerThemeData(
|
|
||||||
color: scheme.outlineVariant,
|
|
||||||
space: 0,
|
|
||||||
),
|
|
||||||
listTileTheme: ListTileThemeData(
|
|
||||||
style: ListTileStyle.list,
|
|
||||||
iconColor: scheme.onSurface,
|
|
||||||
textColor: scheme.onSurface,
|
|
||||||
),
|
|
||||||
scaffoldBackgroundColor: scheme.surface,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorScheme _colorSchemeFromColor() {
|
|
||||||
final scheme = brightness == Brightness.light
|
|
||||||
? Scheme.light(primaryColor.value)
|
|
||||||
: Scheme.dark(primaryColor.value);
|
|
||||||
|
|
||||||
return ColorScheme(
|
|
||||||
brightness: brightness,
|
|
||||||
background: Color(scheme.background),
|
|
||||||
error: Color(scheme.error),
|
|
||||||
errorContainer: Color(scheme.errorContainer),
|
|
||||||
onBackground: Color(scheme.onBackground),
|
|
||||||
onError: Color(scheme.onError),
|
|
||||||
onErrorContainer: Color(scheme.onErrorContainer),
|
|
||||||
primary: Color(scheme.primary),
|
|
||||||
onPrimary: Color(scheme.onPrimary),
|
|
||||||
primaryContainer: Color(scheme.primaryContainer),
|
|
||||||
onPrimaryContainer: Color(scheme.onPrimaryContainer),
|
|
||||||
secondary: Color(scheme.secondary),
|
|
||||||
onSecondary: Color(scheme.onSecondary),
|
|
||||||
surface: Color.alphaBlend(
|
|
||||||
Color(scheme.primary).withOpacity(0.05),
|
|
||||||
Color(scheme.background),
|
|
||||||
),
|
|
||||||
onSurface: Color(scheme.onSurface),
|
|
||||||
surfaceVariant: Color.alphaBlend(
|
|
||||||
Color(scheme.primary).withOpacity(0.5),
|
|
||||||
Color(scheme.background),
|
|
||||||
),
|
|
||||||
onSurfaceVariant: Color(scheme.onSurfaceVariant),
|
|
||||||
outline: Color(scheme.outline),
|
|
||||||
outlineVariant: Color(scheme.outlineVariant),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
295
lib/providers/user_preferences_provider.dart
Normal file
295
lib/providers/user_preferences_provider.dart
Normal file
|
@ -0,0 +1,295 @@
|
||||||
|
import 'package:dynamic_color/dynamic_color.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/scheduler.dart';
|
||||||
|
import 'package:lightmeter/data/models/dynamic_colors_state.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/theme_type.dart';
|
||||||
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
|
import 'package:lightmeter/res/theme.dart';
|
||||||
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
|
class UserPreferencesProvider extends StatefulWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const UserPreferencesProvider({required this.child, super.key});
|
||||||
|
|
||||||
|
static _UserPreferencesProviderState of(BuildContext context) {
|
||||||
|
return context.findAncestorStateOfType<_UserPreferencesProviderState>()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DynamicColorState dynamicColorStateOf(BuildContext context) {
|
||||||
|
return _inheritFromEnumsModel(context, _Aspect.dynamicColorState).dynamicColorState;
|
||||||
|
}
|
||||||
|
|
||||||
|
static EvSourceType evSourceTypeOf(BuildContext context) {
|
||||||
|
return _inheritFromEnumsModel(context, _Aspect.evSourceType).evSourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SupportedLocale localeOf(BuildContext context) {
|
||||||
|
return _inheritFromEnumsModel(context, _Aspect.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 StopType stopTypeOf(BuildContext context) {
|
||||||
|
return _inheritFromEnumsModel(context, _Aspect.stopType).stopType;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ThemeData themeOf(BuildContext context) {
|
||||||
|
return _inheritFromEnumsModel(context, _Aspect.theme).theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ThemeType themeTypeOf(BuildContext context) {
|
||||||
|
return _inheritFromEnumsModel(context, _Aspect.themeType).themeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
static _UserPreferencesModel _inheritFromEnumsModel(
|
||||||
|
BuildContext context,
|
||||||
|
_Aspect aspect,
|
||||||
|
) {
|
||||||
|
return InheritedModel.inheritFrom<_UserPreferencesModel>(context, aspect: aspect)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<UserPreferencesProvider> createState() => _UserPreferencesProviderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||||
|
with WidgetsBindingObserver {
|
||||||
|
UserPreferencesService get userPreferencesService =>
|
||||||
|
ServicesProvider.of(context).userPreferencesService;
|
||||||
|
|
||||||
|
late bool dynamicColor = userPreferencesService.dynamicColor;
|
||||||
|
late EvSourceType evSourceType;
|
||||||
|
late MeteringScreenLayoutConfig meteringScreenLayout =
|
||||||
|
userPreferencesService.meteringScreenLayout;
|
||||||
|
late Color primaryColor = userPreferencesService.primaryColor;
|
||||||
|
late StopType stopType = userPreferencesService.stopType;
|
||||||
|
late SupportedLocale locale = userPreferencesService.locale;
|
||||||
|
late ThemeType themeType = userPreferencesService.themeType;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
evSourceType = userPreferencesService.evSourceType;
|
||||||
|
evSourceType = evSourceType == EvSourceType.sensor &&
|
||||||
|
!ServicesProvider.of(context).environment.hasLightSensor
|
||||||
|
? EvSourceType.camera
|
||||||
|
: evSourceType;
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangePlatformBrightness() {
|
||||||
|
super.didChangePlatformBrightness();
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return DynamicColorBuilder(
|
||||||
|
builder: (lightDynamic, darkDynamic) {
|
||||||
|
late final DynamicColorState state;
|
||||||
|
late final Color? dynamicPrimaryColor;
|
||||||
|
if (lightDynamic != null && darkDynamic != null) {
|
||||||
|
if (dynamicColor) {
|
||||||
|
dynamicPrimaryColor =
|
||||||
|
(_themeBrightness == Brightness.light ? lightDynamic : darkDynamic).primary;
|
||||||
|
state = DynamicColorState.enabled;
|
||||||
|
} else {
|
||||||
|
dynamicPrimaryColor = null;
|
||||||
|
state = DynamicColorState.disabled;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dynamicPrimaryColor = null;
|
||||||
|
state = DynamicColorState.unavailable;
|
||||||
|
}
|
||||||
|
return _UserPreferencesModel(
|
||||||
|
brightness: _themeBrightness,
|
||||||
|
dynamicColorState: state,
|
||||||
|
evSourceType: evSourceType,
|
||||||
|
locale: locale,
|
||||||
|
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
||||||
|
stopType: stopType,
|
||||||
|
themeType: themeType,
|
||||||
|
child: _MeteringScreenLayoutModel(
|
||||||
|
data: meteringScreenLayout,
|
||||||
|
child: widget.child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void enableDynamicColor(bool enable) {
|
||||||
|
setState(() {
|
||||||
|
dynamicColor = enable;
|
||||||
|
});
|
||||||
|
userPreferencesService.dynamicColor = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleEvSourceType() {
|
||||||
|
if (!ServicesProvider.of(context).environment.hasLightSensor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
switch (evSourceType) {
|
||||||
|
case EvSourceType.camera:
|
||||||
|
evSourceType = EvSourceType.sensor;
|
||||||
|
case EvSourceType.sensor:
|
||||||
|
evSourceType = EvSourceType.camera;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
userPreferencesService.evSourceType = evSourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLocale(SupportedLocale locale) {
|
||||||
|
S.load(Locale(locale.intlName)).then((value) {
|
||||||
|
setState(() {
|
||||||
|
this.locale = locale;
|
||||||
|
});
|
||||||
|
userPreferencesService.locale = locale;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMeteringScreenLayout(MeteringScreenLayoutConfig config) {
|
||||||
|
setState(() {
|
||||||
|
meteringScreenLayout = config;
|
||||||
|
});
|
||||||
|
userPreferencesService.meteringScreenLayout = meteringScreenLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPrimaryColor(Color primaryColor) {
|
||||||
|
setState(() {
|
||||||
|
this.primaryColor = primaryColor;
|
||||||
|
});
|
||||||
|
userPreferencesService.primaryColor = primaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setStopType(StopType stopType) {
|
||||||
|
setState(() {
|
||||||
|
this.stopType = stopType;
|
||||||
|
});
|
||||||
|
userPreferencesService.stopType = stopType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setThemeType(ThemeType themeType) {
|
||||||
|
setState(() {
|
||||||
|
this.themeType = themeType;
|
||||||
|
});
|
||||||
|
userPreferencesService.themeType = themeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
Brightness get _themeBrightness {
|
||||||
|
switch (themeType) {
|
||||||
|
case ThemeType.light:
|
||||||
|
return Brightness.light;
|
||||||
|
case ThemeType.dark:
|
||||||
|
return Brightness.dark;
|
||||||
|
case ThemeType.systemDefault:
|
||||||
|
return SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum _Aspect {
|
||||||
|
dynamicColorState,
|
||||||
|
evSourceType,
|
||||||
|
locale,
|
||||||
|
stopType,
|
||||||
|
theme,
|
||||||
|
themeType,
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UserPreferencesModel extends InheritedModel<_Aspect> {
|
||||||
|
final DynamicColorState dynamicColorState;
|
||||||
|
final EvSourceType evSourceType;
|
||||||
|
final SupportedLocale locale;
|
||||||
|
final StopType stopType;
|
||||||
|
final ThemeType themeType;
|
||||||
|
|
||||||
|
final Brightness _brightness;
|
||||||
|
final Color _primaryColor;
|
||||||
|
|
||||||
|
const _UserPreferencesModel({
|
||||||
|
required Brightness brightness,
|
||||||
|
required this.dynamicColorState,
|
||||||
|
required this.evSourceType,
|
||||||
|
required this.locale,
|
||||||
|
required Color primaryColor,
|
||||||
|
required this.stopType,
|
||||||
|
required this.themeType,
|
||||||
|
required super.child,
|
||||||
|
}) : _brightness = brightness,
|
||||||
|
_primaryColor = primaryColor;
|
||||||
|
|
||||||
|
ThemeData get theme => themeFrom(_primaryColor, _brightness);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(_UserPreferencesModel oldWidget) {
|
||||||
|
return _brightness != oldWidget._brightness ||
|
||||||
|
dynamicColorState != oldWidget.dynamicColorState ||
|
||||||
|
evSourceType != oldWidget.evSourceType ||
|
||||||
|
locale != oldWidget.locale ||
|
||||||
|
_primaryColor != oldWidget._primaryColor ||
|
||||||
|
stopType != oldWidget.stopType ||
|
||||||
|
themeType != oldWidget.themeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotifyDependent(
|
||||||
|
_UserPreferencesModel oldWidget,
|
||||||
|
Set<_Aspect> dependencies,
|
||||||
|
) {
|
||||||
|
return (dependencies.contains(_Aspect.dynamicColorState) &&
|
||||||
|
dynamicColorState != oldWidget.dynamicColorState) ||
|
||||||
|
(dependencies.contains(_Aspect.evSourceType) && evSourceType != oldWidget.evSourceType) ||
|
||||||
|
(dependencies.contains(_Aspect.locale) && locale != oldWidget.locale) ||
|
||||||
|
(dependencies.contains(_Aspect.stopType) && stopType != oldWidget.stopType) ||
|
||||||
|
(dependencies.contains(_Aspect.theme) &&
|
||||||
|
(_brightness != oldWidget._brightness || _primaryColor != oldWidget._primaryColor)) ||
|
||||||
|
(dependencies.contains(_Aspect.themeType) && themeType != oldWidget.themeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
97
lib/res/theme.dart
Normal file
97
lib/res/theme.dart
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
import 'package:material_color_utilities/material_color_utilities.dart';
|
||||||
|
|
||||||
|
const primaryColorsList = [
|
||||||
|
Color(0xfff44336),
|
||||||
|
Color(0xffe91e63),
|
||||||
|
Color(0xff9c27b0),
|
||||||
|
Color(0xff673ab7),
|
||||||
|
Color(0xff3f51b5),
|
||||||
|
Color(0xff2196f3),
|
||||||
|
Color(0xff03a9f4),
|
||||||
|
Color(0xff00bcd4),
|
||||||
|
Color(0xff009688),
|
||||||
|
Color(0xff4caf50),
|
||||||
|
Color(0xff8bc34a),
|
||||||
|
Color(0xffcddc39),
|
||||||
|
Color(0xffffeb3b),
|
||||||
|
Color(0xffffc107),
|
||||||
|
Color(0xffff9800),
|
||||||
|
Color(0xffff5722),
|
||||||
|
];
|
||||||
|
|
||||||
|
ThemeData themeFrom(Color primaryColor, Brightness brightness) {
|
||||||
|
final scheme = _colorSchemeFromColor(primaryColor, brightness);
|
||||||
|
return ThemeData(
|
||||||
|
useMaterial3: true,
|
||||||
|
brightness: scheme.brightness,
|
||||||
|
primaryColor: primaryColor,
|
||||||
|
colorScheme: scheme,
|
||||||
|
appBarTheme: AppBarTheme(
|
||||||
|
elevation: 4,
|
||||||
|
color: scheme.surface,
|
||||||
|
surfaceTintColor: scheme.surfaceTint,
|
||||||
|
),
|
||||||
|
cardTheme: CardTheme(
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
color: scheme.surface,
|
||||||
|
elevation: 4,
|
||||||
|
margin: EdgeInsets.zero,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(Dimens.borderRadiusL)),
|
||||||
|
surfaceTintColor: scheme.surfaceTint,
|
||||||
|
),
|
||||||
|
dialogBackgroundColor: scheme.surface,
|
||||||
|
dialogTheme: DialogTheme(
|
||||||
|
backgroundColor: scheme.surface,
|
||||||
|
surfaceTintColor: scheme.surfaceTint,
|
||||||
|
elevation: 6,
|
||||||
|
),
|
||||||
|
dividerColor: scheme.outlineVariant,
|
||||||
|
dividerTheme: DividerThemeData(
|
||||||
|
color: scheme.outlineVariant,
|
||||||
|
space: 0,
|
||||||
|
),
|
||||||
|
listTileTheme: ListTileThemeData(
|
||||||
|
style: ListTileStyle.list,
|
||||||
|
iconColor: scheme.onSurface,
|
||||||
|
textColor: scheme.onSurface,
|
||||||
|
),
|
||||||
|
scaffoldBackgroundColor: scheme.surface,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorScheme _colorSchemeFromColor(Color primaryColor, Brightness brightness) {
|
||||||
|
final scheme = brightness == Brightness.light
|
||||||
|
? Scheme.light(primaryColor.value)
|
||||||
|
: Scheme.dark(primaryColor.value);
|
||||||
|
|
||||||
|
return ColorScheme(
|
||||||
|
brightness: brightness,
|
||||||
|
background: Color(scheme.background),
|
||||||
|
error: Color(scheme.error),
|
||||||
|
errorContainer: Color(scheme.errorContainer),
|
||||||
|
onBackground: Color(scheme.onBackground),
|
||||||
|
onError: Color(scheme.onError),
|
||||||
|
onErrorContainer: Color(scheme.onErrorContainer),
|
||||||
|
primary: Color(scheme.primary),
|
||||||
|
onPrimary: Color(scheme.onPrimary),
|
||||||
|
primaryContainer: Color(scheme.primaryContainer),
|
||||||
|
onPrimaryContainer: Color(scheme.onPrimaryContainer),
|
||||||
|
secondary: Color(scheme.secondary),
|
||||||
|
onSecondary: Color(scheme.onSecondary),
|
||||||
|
surface: Color.alphaBlend(
|
||||||
|
Color(scheme.primary).withOpacity(0.05),
|
||||||
|
Color(scheme.background),
|
||||||
|
),
|
||||||
|
onSurface: Color(scheme.onSurface),
|
||||||
|
surfaceVariant: Color.alphaBlend(
|
||||||
|
Color(scheme.primary).withOpacity(0.5),
|
||||||
|
Color(scheme.background),
|
||||||
|
),
|
||||||
|
onSurfaceVariant: Color(scheme.onSurfaceVariant),
|
||||||
|
outline: Color(scheme.outline),
|
||||||
|
outlineVariant: Color(scheme.outlineVariant),
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
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/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';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class MeteringBottomControls extends StatelessWidget {
|
class MeteringBottomControls extends StatelessWidget {
|
||||||
final double? ev;
|
final double? ev;
|
||||||
|
@ -42,7 +42,7 @@ class MeteringBottomControls extends StatelessWidget {
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
onPressed: onSwitchEvSourceType,
|
onPressed: onSwitchEvSourceType,
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
context.listen<EvSourceType>() != EvSourceType.camera
|
UserPreferencesProvider.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/metering_screen_layout_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_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 (MeteringScreenLayout.featureOf(
|
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.histogram,
|
MeteringScreenLayoutFeature.histogram,
|
||||||
))
|
))
|
||||||
|
|
|
@ -2,12 +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/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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/metering/flow_metering.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 {
|
||||||
|
@ -39,7 +38,7 @@ class CameraContainerProvider extends StatelessWidget {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => CameraContainerBloc(
|
create: (context) => CameraContainerBloc(
|
||||||
context.get<MeteringInteractor>(),
|
MeteringInteractorProvider.of(context),
|
||||||
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/metering_screen_layout_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_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 (MeteringScreenLayout.featureOf(
|
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs,
|
MeteringScreenLayoutFeature.extremeExposurePairs,
|
||||||
)) {
|
)) {
|
||||||
enabledFeaturesHeight += Dimens.readingContainerDoubleValueHeight;
|
enabledFeaturesHeight += Dimens.readingContainerDoubleValueHeight;
|
||||||
enabledFeaturesHeight += Dimens.paddingS;
|
enabledFeaturesHeight += Dimens.paddingS;
|
||||||
}
|
}
|
||||||
if (MeteringScreenLayout.featureOf(
|
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.filmPicker,
|
MeteringScreenLayoutFeature.filmPicker,
|
||||||
)) {
|
)) {
|
||||||
|
|
|
@ -2,11 +2,10 @@ 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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/metering/flow_metering.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 {
|
||||||
|
@ -38,7 +37,7 @@ class LightSensorContainerProvider extends StatelessWidget {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => LightSensorContainerBloc(
|
create: (context) => LightSensorContainerBloc(
|
||||||
context.get<MeteringInteractor>(),
|
MeteringInteractorProvider.of(context),
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
),
|
),
|
||||||
child: LightSensorContainer(
|
child: LightSensorContainer(
|
||||||
|
|
|
@ -5,11 +5,10 @@ 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/metering_screen_layout_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_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 {
|
||||||
|
@ -43,7 +42,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
const _EquipmentProfilePicker(),
|
const _EquipmentProfilePicker(),
|
||||||
const _InnerPadding(),
|
const _InnerPadding(),
|
||||||
],
|
],
|
||||||
if (MeteringScreenLayout.featureOf(
|
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs,
|
MeteringScreenLayoutFeature.extremeExposurePairs,
|
||||||
)) ...[
|
)) ...[
|
||||||
|
@ -61,7 +60,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const _InnerPadding(),
|
const _InnerPadding(),
|
||||||
],
|
],
|
||||||
if (MeteringScreenLayout.featureOf(
|
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.filmPicker,
|
MeteringScreenLayoutFeature.filmPicker,
|
||||||
)) ...[
|
)) ...[
|
||||||
|
@ -77,7 +76,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _IsoValuePicker(
|
child: _IsoValuePicker(
|
||||||
selectedValue: iso,
|
selectedValue: iso,
|
||||||
values: context.listen<EquipmentProfile>().isoValues,
|
values: EquipmentProfiles.selectedOf(context).isoValues,
|
||||||
onChanged: onIsoChanged,
|
onChanged: onIsoChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -85,7 +84,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _NdValuePicker(
|
child: _NdValuePicker(
|
||||||
selectedValue: nd,
|
selectedValue: nd,
|
||||||
values: context.listen<EquipmentProfile>().ndValues,
|
values: EquipmentProfiles.selectedOf(context).ndValues,
|
||||||
onChanged: onNdChanged,
|
onChanged: onNdChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -108,16 +107,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: context.listen<EquipmentProfile>(),
|
selectedValue: EquipmentProfiles.selectedOf(context),
|
||||||
values: context.listen<EquipmentProfiles>(),
|
values: EquipmentProfiles.of(context),
|
||||||
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: context.listen<EquipmentProfile>().id.isEmpty
|
value: EquipmentProfiles.selectedOf(context).id.isEmpty
|
||||||
? S.of(context).none
|
? S.of(context).none
|
||||||
: context.listen<EquipmentProfile>().name,
|
: EquipmentProfiles.selectedOf(context).name,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
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/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/interactors/metering_interactor.dart';
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
||||||
|
import 'package:lightmeter/providers/services_provider.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});
|
||||||
|
@ -23,31 +17,45 @@ 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 InheritedWidgetBase<MeteringInteractor>(
|
return MeteringInteractorProvider(
|
||||||
data: MeteringInteractor(
|
data: MeteringInteractor(
|
||||||
context.get<UserPreferencesService>(),
|
ServicesProvider.of(context).userPreferencesService,
|
||||||
context.get<CaffeineService>(),
|
ServicesProvider.of(context).caffeineService,
|
||||||
context.get<HapticsService>(),
|
ServicesProvider.of(context).hapticsService,
|
||||||
context.get<PermissionsService>(),
|
ServicesProvider.of(context).permissionsService,
|
||||||
context.get<LightSensorService>(),
|
ServicesProvider.of(context).lightSensorService,
|
||||||
context.get<VolumeEventsService>(),
|
ServicesProvider.of(context).volumeEventsService,
|
||||||
)..initialize(),
|
)..initialize(),
|
||||||
child: InheritedWidgetBase<VolumeKeysNotifier>(
|
child: MultiBlocProvider(
|
||||||
data: VolumeKeysNotifier(context.get<VolumeEventsService>()),
|
providers: [
|
||||||
child: MultiBlocProvider(
|
BlocProvider(create: (_) => MeteringCommunicationBloc()),
|
||||||
providers: [
|
BlocProvider(
|
||||||
BlocProvider(create: (_) => MeteringCommunicationBloc()),
|
create: (context) => MeteringBloc(
|
||||||
BlocProvider(
|
MeteringInteractorProvider.of(context),
|
||||||
create: (context) => MeteringBloc(
|
VolumeKeysNotifier(ServicesProvider.of(context).volumeEventsService),
|
||||||
context.get<MeteringInteractor>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
context.get<VolumeKeysNotifier>(),
|
|
||||||
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,15 +6,17 @@ 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/environment.dart';
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
import 'package:lightmeter/providers/ev_source_type_provider.dart';
|
import 'package:lightmeter/providers/services_provider.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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/metering/utils/listener_metering_layout_feature.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 {
|
||||||
|
@ -45,8 +47,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: context.get<Environment>().hasLightSensor
|
onSwitchEvSourceType: ServicesProvider.of(context).environment.hasLightSensor
|
||||||
? EvSourceTypeProvider.of(context).toggleType
|
? UserPreferencesProvider.of(context).toggleEvSourceType
|
||||||
: null,
|
: null,
|
||||||
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
||||||
onSettings: () {
|
onSettings: () {
|
||||||
|
@ -71,12 +73,12 @@ class _InheritedListeners extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InheritedWidgetListener<EquipmentProfile>(
|
return EquipmentProfileListener(
|
||||||
onDidChangeDependencies: (value) {
|
onDidChangeDependencies: (value) {
|
||||||
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
||||||
},
|
},
|
||||||
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
child: MeteringScreenLayoutFeatureListener(
|
||||||
aspect: MeteringScreenLayoutFeature.filmPicker,
|
feature: 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()));
|
||||||
},
|
},
|
||||||
|
@ -110,7 +112,8 @@ class _MeteringContainerBuidler extends StatelessWidget {
|
||||||
final exposurePairs = ev != null ? buildExposureValues(context, ev!, film) : <ExposurePair>[];
|
final exposurePairs = ev != null ? buildExposureValues(context, ev!, film) : <ExposurePair>[];
|
||||||
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;
|
||||||
return context.listen<EvSourceType>() == EvSourceType.camera
|
// Doubled build here when switching evSourceType. As new source bloc fires a new state on init
|
||||||
|
return UserPreferencesProvider.evSourceTypeOf(context) == EvSourceType.camera
|
||||||
? CameraContainerProvider(
|
? CameraContainerProvider(
|
||||||
fastest: fastest,
|
fastest: fastest,
|
||||||
slowest: slowest,
|
slowest: slowest,
|
||||||
|
@ -141,10 +144,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 = context.listen<StopType>();
|
final StopType stopType = UserPreferencesProvider.stopTypeOf(context);
|
||||||
final int evSteps = (ev * (stopType.index + 1)).round();
|
final int evSteps = (ev * (stopType.index + 1)).round();
|
||||||
|
|
||||||
final EquipmentProfile equipmentProfile = context.listen<EquipmentProfile>();
|
final EquipmentProfile equipmentProfile = EquipmentProfiles.selectedOf(context);
|
||||||
final List<ApertureValue> apertureValues =
|
final List<ApertureValue> apertureValues =
|
||||||
equipmentProfile.apertureValues.whereStopType(stopType);
|
equipmentProfile.apertureValues.whereStopType(stopType);
|
||||||
final List<ShutterSpeedValue> shutterSpeedValues =
|
final List<ShutterSpeedValue> shutterSpeedValues =
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
30
lib/screens/metering/utils/listsner_equipment_profiles.dart
Normal file
30
lib/screens/metering/utils/listsner_equipment_profiles.dart
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
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,7 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class ReportIssueListTile extends StatelessWidget {
|
class ReportIssueListTile extends StatelessWidget {
|
||||||
|
@ -14,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(context.get<Environment>().issuesReportUrl),
|
Uri.parse(ServicesProvider.of(context).environment.issuesReportUrl),
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class SourceCodeListTile extends StatelessWidget {
|
class SourceCodeListTile extends StatelessWidget {
|
||||||
|
@ -14,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(context.get<Environment>().sourceCodeUrl),
|
Uri.parse(ServicesProvider.of(context).environment.sourceCodeUrl),
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +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/environment.dart';
|
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class WriteEmailListTile extends StatelessWidget {
|
class WriteEmailListTile extends StatelessWidget {
|
||||||
|
@ -14,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 = context.get<Environment>().contactEmail;
|
final email = ServicesProvider.of(context).environment.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,10 +1,9 @@
|
||||||
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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
||||||
|
|
||||||
class CaffeineListTileProvider extends StatelessWidget {
|
class CaffeineListTileProvider extends StatelessWidget {
|
||||||
const CaffeineListTileProvider({super.key});
|
const CaffeineListTileProvider({super.key});
|
||||||
|
@ -12,7 +11,7 @@ class CaffeineListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CaffeineListTileBloc(context.get<SettingsInteractor>()),
|
create: (context) => CaffeineListTileBloc(SettingsInteractorProvider.of(context)),
|
||||||
child: const CaffeineListTile(),
|
child: const CaffeineListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
||||||
|
|
||||||
class HapticsListTileProvider extends StatelessWidget {
|
class HapticsListTileProvider extends StatelessWidget {
|
||||||
const HapticsListTileProvider({super.key});
|
const HapticsListTileProvider({super.key});
|
||||||
|
@ -12,7 +11,7 @@ class HapticsListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => HapticsListTileBloc(context.get<SettingsInteractor>()),
|
create: (context) => HapticsListTileBloc(SettingsInteractorProvider.of(context)),
|
||||||
child: const HapticsListTile(),
|
child: const HapticsListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
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/supported_locale_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_provider.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:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class LanguageListTile extends StatelessWidget {
|
class LanguageListTile extends StatelessWidget {
|
||||||
const LanguageListTile({super.key});
|
const LanguageListTile({super.key});
|
||||||
|
@ -13,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(context.listen<SupportedLocale>().localizedName),
|
trailing: Text(UserPreferencesProvider.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: context.get<SupportedLocale>(),
|
selectedValue: UserPreferencesProvider.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) {
|
||||||
SupportedLocaleProvider.of(context).setLocale(value);
|
UserPreferencesProvider.of(context).setLocale(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
||||||
|
|
||||||
class VolumeActionsListTileProvider extends StatelessWidget {
|
class VolumeActionsListTileProvider extends StatelessWidget {
|
||||||
const VolumeActionsListTileProvider({super.key});
|
const VolumeActionsListTileProvider({super.key});
|
||||||
|
@ -12,7 +11,7 @@ class VolumeActionsListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => VolumeActionsListTileBloc(context.get<SettingsInteractor>()),
|
create: (context) => VolumeActionsListTileBloc(SettingsInteractorProvider.of(context)),
|
||||||
child: const VolumeActionsListTile(),
|
child: const VolumeActionsListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
||||||
|
|
||||||
class CalibrationDialogProvider extends StatelessWidget {
|
class CalibrationDialogProvider extends StatelessWidget {
|
||||||
const CalibrationDialogProvider({super.key});
|
const CalibrationDialogProvider({super.key});
|
||||||
|
@ -12,7 +11,7 @@ class CalibrationDialogProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CalibrationDialogBloc(context.get<SettingsInteractor>()),
|
create: (context) => CalibrationDialogBloc(SettingsInteractorProvider.of(context)),
|
||||||
child: const CalibrationDialog(),
|
child: const CalibrationDialog(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +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/environment.dart';
|
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
|
import 'package:lightmeter/providers/services_provider.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';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/state_dialog_calibration.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/calibration/components/calibration_dialog/state_dialog_calibration.dart';
|
||||||
import 'package:lightmeter/screens/shared/centered_slider/widget_slider_centered.dart';
|
import 'package:lightmeter/screens/shared/centered_slider/widget_slider_centered.dart';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
import 'package:lightmeter/utils/to_string_signed.dart';
|
import 'package:lightmeter/utils/to_string_signed.dart';
|
||||||
|
|
||||||
class CalibrationDialog extends StatelessWidget {
|
class CalibrationDialog extends StatelessWidget {
|
||||||
|
@ -15,7 +14,7 @@ class CalibrationDialog extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final bool hasLightSensor = context.get<Environment>().hasLightSensor;
|
final bool hasLightSensor = ServicesProvider.of(context).environment.hasLightSensor;
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
icon: const Icon(Icons.settings_brightness),
|
icon: const Icon(Icons.settings_brightness),
|
||||||
titlePadding: Dimens.dialogIconTitlePadding,
|
titlePadding: Dimens.dialogIconTitlePadding,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
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/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
||||||
|
|
||||||
class CalibrationListTile extends StatelessWidget {
|
class CalibrationListTile extends StatelessWidget {
|
||||||
const CalibrationListTile({super.key});
|
const CalibrationListTile({super.key});
|
||||||
|
@ -15,8 +14,8 @@ class CalibrationListTile extends StatelessWidget {
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showDialog<double>(
|
showDialog<double>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => InheritedWidgetBase(
|
builder: (_) => SettingsInteractorProvider(
|
||||||
data: context.get<SettingsInteractor>(),
|
data: SettingsInteractorProvider.of(context),
|
||||||
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,13 +19,12 @@ 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 => context.listen<EquipmentProfiles>().length;
|
int get profilesCount => EquipmentProfiles.of(context).length;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void didChangeDependencies() {
|
||||||
super.initState();
|
super.didChangeDependencies();
|
||||||
profileContainersKeys = context
|
profileContainersKeys = EquipmentProfiles.of(context)
|
||||||
.get<EquipmentProfiles>()
|
|
||||||
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
|
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
@ -58,14 +57,14 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
),
|
),
|
||||||
child: EquipmentProfileContainer(
|
child: EquipmentProfileContainer(
|
||||||
key: profileContainersKeys[index],
|
key: profileContainersKeys[index],
|
||||||
data: context.listen<EquipmentProfiles>()[index],
|
data: EquipmentProfiles.of(context)[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: profileContainersKeys.length,
|
childCount: profilesCount,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -79,7 +78,6 @@ 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>());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -89,8 +87,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _removeProfileAt(int index) {
|
void _removeProfileAt(int index) {
|
||||||
EquipmentProfileProvider.of(context).deleteProfile(context.listen<EquipmentProfiles>()[index]);
|
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]);
|
||||||
profileContainersKeys.removeAt(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _keepExpandedAt(int index) {
|
void _keepExpandedAt(int index) {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
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/stop_type_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_provider.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:lightmeter/utils/inherited_generics.dart';
|
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class StopTypeListTile extends StatelessWidget {
|
class StopTypeListTile extends StatelessWidget {
|
||||||
|
@ -13,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, context.listen<StopType>())),
|
trailing: Text(_typeToString(context, UserPreferencesProvider.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: context.get<StopType>(),
|
selectedValue: UserPreferencesProvider.stopTypeOf(context),
|
||||||
values: StopType.values,
|
values: StopType.values,
|
||||||
titleAdapter: _typeToString,
|
titleAdapter: _typeToString,
|
||||||
),
|
),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
StopTypeProvider.of(context).set(value);
|
UserPreferencesProvider.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/metering_screen_layout_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_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(MeteringScreenLayout.of(context, listen: false));
|
MeteringScreenLayoutConfig.from(UserPreferencesProvider.meteringScreenConfigOf(context));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -56,7 +56,7 @@ class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayou
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
MeteringScreenLayoutProvider.of(context).updateFeatures(_features);
|
UserPreferencesProvider.of(context).setMeteringScreenLayout(_features);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Text(S.of(context).save),
|
child: Text(S.of(context).save),
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
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/theme_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class DynamicColorListTile extends StatelessWidget {
|
class DynamicColorListTile extends StatelessWidget {
|
||||||
const DynamicColorListTile({super.key});
|
const DynamicColorListTile({super.key});
|
||||||
|
@ -13,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: context.listen<DynamicColorState>() == DynamicColorState.enabled,
|
value: UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled,
|
||||||
onChanged: ThemeProvider.of(context).enableDynamicColor,
|
onChanged: UserPreferencesProvider.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/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/theme_provider.dart';
|
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
import 'package:lightmeter/res/theme.dart';
|
||||||
import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dart';
|
import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dart';
|
||||||
|
|
||||||
class PrimaryColorDialogPicker extends StatefulWidget {
|
class PrimaryColorDialogPicker extends StatefulWidget {
|
||||||
|
@ -38,9 +38,9 @@ class _PrimaryColorDialogPickerState extends State<PrimaryColorDialogPicker> {
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: List.generate(
|
children: List.generate(
|
||||||
ThemeProvider.primaryColorsList.length,
|
primaryColorsList.length,
|
||||||
(index) {
|
(index) {
|
||||||
final color = ThemeProvider.primaryColorsList[index];
|
final color = primaryColorsList[index];
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.only(left: index == 0 ? 0 : Dimens.paddingS),
|
padding: EdgeInsets.only(left: index == 0 ? 0 : Dimens.paddingS),
|
||||||
child: _SelectableColorItem(
|
child: _SelectableColorItem(
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
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/theme_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_provider.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';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class PrimaryColorListTile extends StatelessWidget {
|
class PrimaryColorListTile extends StatelessWidget {
|
||||||
const PrimaryColorListTile({super.key});
|
const PrimaryColorListTile({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (context.listen<DynamicColorState>() == DynamicColorState.enabled) {
|
if (UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled) {
|
||||||
return Opacity(
|
return Opacity(
|
||||||
opacity: Dimens.disabledOpacity,
|
opacity: Dimens.disabledOpacity,
|
||||||
child: IgnorePointer(
|
child: IgnorePointer(
|
||||||
|
@ -31,7 +30,7 @@ class PrimaryColorListTile extends StatelessWidget {
|
||||||
builder: (_) => const PrimaryColorDialogPicker(),
|
builder: (_) => const PrimaryColorDialogPicker(),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
ThemeProvider.of(context).setPrimaryColor(value);
|
UserPreferencesProvider.of(context).setPrimaryColor(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
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/theme_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_provider.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:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class ThemeTypeListTile extends StatelessWidget {
|
class ThemeTypeListTile extends StatelessWidget {
|
||||||
const ThemeTypeListTile({super.key});
|
const ThemeTypeListTile({super.key});
|
||||||
|
@ -13,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, context.listen<ThemeType>())),
|
trailing: Text(_typeToString(context, UserPreferencesProvider.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: context.get<ThemeType>(),
|
selectedValue: UserPreferencesProvider.themeTypeOf(context),
|
||||||
values: ThemeType.values,
|
values: ThemeType.values,
|
||||||
titleAdapter: _typeToString,
|
titleAdapter: _typeToString,
|
||||||
),
|
),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
ThemeProvider.of(context).setThemeType(value);
|
UserPreferencesProvider.of(context).setThemeType(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
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/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';
|
||||||
import 'package:lightmeter/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart';
|
import 'package:lightmeter/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
||||||
|
|
||||||
class ThemeSettingsSection extends StatelessWidget {
|
class ThemeSettingsSection extends StatelessWidget {
|
||||||
const ThemeSettingsSection({super.key});
|
const ThemeSettingsSection({super.key});
|
||||||
|
@ -17,7 +17,7 @@ class ThemeSettingsSection extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
const ThemeTypeListTile(),
|
const ThemeTypeListTile(),
|
||||||
const PrimaryColorListTile(),
|
const PrimaryColorListTile(),
|
||||||
if (context.get<DynamicColorState>() != DynamicColorState.unavailable)
|
if (UserPreferencesProvider.dynamicColorStateOf(context) != DynamicColorState.unavailable)
|
||||||
const DynamicColorListTile(),
|
const DynamicColorListTile(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,25 +1,38 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/caffeine_service.dart';
|
|
||||||
import 'package:lightmeter/data/haptics_service.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
||||||
import 'package:lightmeter/data/volume_events_service.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/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 InheritedWidgetBase<SettingsInteractor>(
|
return SettingsInteractorProvider(
|
||||||
data: SettingsInteractor(
|
data: SettingsInteractor(
|
||||||
context.get<UserPreferencesService>(),
|
ServicesProvider.of(context).userPreferencesService,
|
||||||
context.get<CaffeineService>(),
|
ServicesProvider.of(context).caffeineService,
|
||||||
context.get<HapticsService>(),
|
ServicesProvider.of(context).hapticsService,
|
||||||
context.get<VolumeEventsService>(),
|
ServicesProvider.of(context).volumeEventsService,
|
||||||
),
|
),
|
||||||
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,12 +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/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});
|
||||||
|
@ -19,12 +18,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
context.get<SettingsInteractor>().disableVolumeHandling();
|
SettingsInteractorProvider.of(context).disableVolumeHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void deactivate() {
|
void deactivate() {
|
||||||
context.get<SettingsInteractor>().restoreVolumeHandling();
|
SettingsInteractorProvider.of(context).restoreVolumeHandling();
|
||||||
super.deactivate();
|
super.deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,171 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ 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/providers/theme_provider.dart';
|
import 'package:lightmeter/res/theme.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
import 'package:mocktail/mocktail.dart';
|
import 'package:mocktail/mocktail.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
@ -348,13 +348,13 @@ void main() {
|
||||||
group('primaryColor', () {
|
group('primaryColor', () {
|
||||||
test('get default', () {
|
test('get default', () {
|
||||||
when(() => sharedPreferences.getInt(UserPreferencesService.primaryColorKey)).thenReturn(null);
|
when(() => sharedPreferences.getInt(UserPreferencesService.primaryColorKey)).thenReturn(null);
|
||||||
expect(service.primaryColor, ThemeProvider.primaryColorsList[5]);
|
expect(service.primaryColor, primaryColorsList[5]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('get', () {
|
test('get', () {
|
||||||
when(() => sharedPreferences.getInt(UserPreferencesService.primaryColorKey))
|
when(() => sharedPreferences.getInt(UserPreferencesService.primaryColorKey))
|
||||||
.thenReturn(0xff9c27b0);
|
.thenReturn(0xff9c27b0);
|
||||||
expect(service.primaryColor, ThemeProvider.primaryColorsList[2]);
|
expect(service.primaryColor, primaryColorsList[2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set', () {
|
test('set', () {
|
||||||
|
|
Loading…
Reference in a new issue