mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 00:10:47 +00:00
ML-77 Redundant vibrations (#76)
* wip * `MeteringScreenLayout = InheritedModelBase<MeteringScreenLayoutFeature, bool>` * removed `Provider` from providers folder * wip * Update pubspec.yaml * `context.get<MeteringInteractor>()` * `context.get<Environment>()` * `context.get<SettingsInteractor>()` * typo * fixed `MeteringScreenLayout` * fixed redundant vibrations
This commit is contained in:
parent
a0eb641cf3
commit
cdf7372913
35 changed files with 505 additions and 327 deletions
|
@ -1,26 +1,13 @@
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
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/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers.dart';
|
||||||
import 'package:lightmeter/providers/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/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:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
class Application extends StatelessWidget {
|
class Application extends StatelessWidget {
|
||||||
final Environment env;
|
final Environment env;
|
||||||
|
@ -29,34 +16,13 @@ class Application extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder(
|
return LightmeterProviders(
|
||||||
future: Future.wait([
|
env: env,
|
||||||
SharedPreferences.getInstance(),
|
builder: (context, ready) => ready
|
||||||
if (Platform.isAndroid) const LightSensorService().hasSensor() else Future.value(false),
|
? _AnnotatedRegionWrapper(
|
||||||
]),
|
|
||||||
builder: (_, snapshot) {
|
|
||||||
if (snapshot.data != null) {
|
|
||||||
return MultiProvider(
|
|
||||||
providers: [
|
|
||||||
Provider.value(value: env.copyWith(hasLightSensor: snapshot.data![1] as bool)),
|
|
||||||
Provider(
|
|
||||||
create: (_) => UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
|
||||||
),
|
|
||||||
Provider(create: (_) => const CaffeineService()),
|
|
||||||
Provider(create: (_) => const HapticsService()),
|
|
||||||
Provider(create: (_) => PermissionsService()),
|
|
||||||
Provider(create: (_) => const LightSensorService()),
|
|
||||||
],
|
|
||||||
child: MeteringScreenLayoutProvider(
|
|
||||||
child: StopTypeProvider(
|
|
||||||
child: EquipmentProfileProvider(
|
|
||||||
child: EvSourceTypeProvider(
|
|
||||||
child: SupportedLocaleProvider(
|
|
||||||
child: ThemeProvider(
|
|
||||||
builder: (context, _) => _AnnotatedRegionWrapper(
|
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
theme: context.watch<ThemeData>(),
|
theme: context.listen<ThemeData>(),
|
||||||
locale: Locale(context.watch<SupportedLocale>().intlName),
|
locale: Locale(context.listen<SupportedLocale>().intlName),
|
||||||
localizationsDelegates: const [
|
localizationsDelegates: const [
|
||||||
S.delegate,
|
S.delegate,
|
||||||
GlobalMaterialLocalizations.delegate,
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
@ -74,20 +40,8 @@ class Application extends StatelessWidget {
|
||||||
"settings": (context) => const SettingsFlow(),
|
"settings": (context) => const SettingsFlow(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
),
|
: const SizedBox(),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (snapshot.error != null) {
|
|
||||||
return Center(child: Text(snapshot.error!.toString()));
|
|
||||||
} else {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +54,7 @@ class _AnnotatedRegionWrapper extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final systemIconsBrightness = ThemeData.estimateBrightnessForColor(
|
final systemIconsBrightness = ThemeData.estimateBrightnessForColor(
|
||||||
context.watch<ThemeData>().colorScheme.onSurface,
|
context.listen<ThemeData>().colorScheme.onSurface,
|
||||||
);
|
);
|
||||||
return AnnotatedRegion(
|
return AnnotatedRegion(
|
||||||
value: SystemUiOverlayStyle(
|
value: SystemUiOverlayStyle(
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class PermissionsService {
|
class PermissionsService {
|
||||||
|
const PermissionsService();
|
||||||
|
|
||||||
Future<PermissionStatus> checkCameraPermission() async => Permission.camera.status;
|
Future<PermissionStatus> checkCameraPermission() async => Permission.camera.status;
|
||||||
|
|
||||||
Future<PermissionStatus> requestCameraPermission() async => Permission.camera.request();
|
Future<PermissionStatus> requestCameraPermission() async => Permission.camera.request();
|
||||||
|
|
74
lib/providers.dart
Normal file
74
lib/providers.dart
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
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/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: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(),
|
||||||
|
if (Platform.isAndroid) const LightSensorService().hasSensor() else Future.value(false),
|
||||||
|
]),
|
||||||
|
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(),
|
||||||
|
child: InheritedWidgetBase<CaffeineService>(
|
||||||
|
data: const CaffeineService(),
|
||||||
|
child: InheritedWidgetBase<HapticsService>(
|
||||||
|
data: const HapticsService(),
|
||||||
|
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,9 +1,12 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/shared_prefs_service.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';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
typedef EquipmentProfiles = List<EquipmentProfileData>;
|
||||||
|
typedef EquipmentProfile = EquipmentProfileData;
|
||||||
|
|
||||||
class EquipmentProfileProvider extends StatefulWidget {
|
class EquipmentProfileProvider extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
|
@ -33,7 +36,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
EquipmentProfileData get _selectedProfile => _customProfiles.firstWhere(
|
EquipmentProfileData get _selectedProfile => _customProfiles.firstWhere(
|
||||||
(e) => e.id == _selectedId,
|
(e) => e.id == _selectedId,
|
||||||
orElse: () {
|
orElse: () {
|
||||||
context.read<UserPreferencesService>().selectedEquipmentProfileId = _defaultProfile.id;
|
context.get<UserPreferencesService>().selectedEquipmentProfileId = _defaultProfile.id;
|
||||||
return _defaultProfile;
|
return _defaultProfile;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -41,15 +44,15 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_selectedId = context.read<UserPreferencesService>().selectedEquipmentProfileId;
|
_selectedId = context.get<UserPreferencesService>().selectedEquipmentProfileId;
|
||||||
_customProfiles = context.read<UserPreferencesService>().equipmentProfiles;
|
_customProfiles = context.get<UserPreferencesService>().equipmentProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return EquipmentProfiles(
|
return InheritedWidgetBase<List<EquipmentProfileData>>(
|
||||||
profiles: [_defaultProfile] + _customProfiles,
|
data: [_defaultProfile] + _customProfiles,
|
||||||
child: EquipmentProfile(
|
child: InheritedWidgetBase<EquipmentProfileData>(
|
||||||
data: _selectedProfile,
|
data: _selectedProfile,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
|
@ -60,7 +63,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedId = data.id;
|
_selectedId = data.id;
|
||||||
});
|
});
|
||||||
context.read<UserPreferencesService>().selectedEquipmentProfileId = _selectedProfile.id;
|
context.get<UserPreferencesService>().selectedEquipmentProfileId = _selectedProfile.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a default equipment profile
|
/// Creates a default equipment profile
|
||||||
|
@ -92,49 +95,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _refreshSavedProfiles() {
|
void _refreshSavedProfiles() {
|
||||||
context.read<UserPreferencesService>().equipmentProfiles = _customProfiles;
|
context.get<UserPreferencesService>().equipmentProfiles = _customProfiles;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EquipmentProfiles extends InheritedWidget {
|
|
||||||
final List<EquipmentProfileData> profiles;
|
|
||||||
|
|
||||||
const EquipmentProfiles({
|
|
||||||
required this.profiles,
|
|
||||||
required super.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
static List<EquipmentProfileData> of(BuildContext context, {bool listen = true}) {
|
|
||||||
if (listen) {
|
|
||||||
return context.dependOnInheritedWidgetOfExactType<EquipmentProfiles>()!.profiles;
|
|
||||||
} else {
|
|
||||||
return context.findAncestorWidgetOfExactType<EquipmentProfiles>()!.profiles;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(EquipmentProfiles oldWidget) => true;
|
|
||||||
}
|
|
||||||
|
|
||||||
class EquipmentProfile extends InheritedWidget {
|
|
||||||
final EquipmentProfileData data;
|
|
||||||
|
|
||||||
const EquipmentProfile({
|
|
||||||
required this.data,
|
|
||||||
required super.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
static EquipmentProfileData of(BuildContext context, {bool listen = true}) {
|
|
||||||
if (listen) {
|
|
||||||
return context.dependOnInheritedWidgetOfExactType<EquipmentProfile>()!.data;
|
|
||||||
} else {
|
|
||||||
return context.findAncestorWidgetOfExactType<EquipmentProfile>()!.data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(EquipmentProfile oldWidget) => true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class EvSourceTypeProvider extends StatefulWidget {
|
class EvSourceTypeProvider extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
@ -23,9 +23,9 @@ class EvSourceTypeProviderState extends State<EvSourceTypeProvider> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final evSourceType = context.read<UserPreferencesService>().evSourceType;
|
final evSourceType = context.get<UserPreferencesService>().evSourceType;
|
||||||
valueListenable = ValueNotifier(
|
valueListenable = ValueNotifier(
|
||||||
evSourceType == EvSourceType.sensor && !context.read<Environment>().hasLightSensor
|
evSourceType == EvSourceType.sensor && !context.get<Environment>().hasLightSensor
|
||||||
? EvSourceType.camera
|
? EvSourceType.camera
|
||||||
: evSourceType,
|
: evSourceType,
|
||||||
);
|
);
|
||||||
|
@ -41,9 +41,9 @@ class EvSourceTypeProviderState extends State<EvSourceTypeProvider> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ValueListenableBuilder(
|
return ValueListenableBuilder(
|
||||||
valueListenable: valueListenable,
|
valueListenable: valueListenable,
|
||||||
builder: (_, value, child) => Provider.value(
|
builder: (_, value, child) => InheritedWidgetBase<EvSourceType>(
|
||||||
value: value,
|
data: value,
|
||||||
child: child,
|
child: child!,
|
||||||
),
|
),
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
|
@ -52,12 +52,12 @@ class EvSourceTypeProviderState extends State<EvSourceTypeProvider> {
|
||||||
void toggleType() {
|
void toggleType() {
|
||||||
switch (valueListenable.value) {
|
switch (valueListenable.value) {
|
||||||
case EvSourceType.camera:
|
case EvSourceType.camera:
|
||||||
if (context.read<Environment>().hasLightSensor) {
|
if (context.get<Environment>().hasLightSensor) {
|
||||||
valueListenable.value = EvSourceType.sensor;
|
valueListenable.value = EvSourceType.sensor;
|
||||||
}
|
}
|
||||||
case EvSourceType.sensor:
|
case EvSourceType.sensor:
|
||||||
valueListenable.value = EvSourceType.camera;
|
valueListenable.value = EvSourceType.camera;
|
||||||
}
|
}
|
||||||
context.read<UserPreferencesService>().evSourceType = valueListenable.value;
|
context.get<UserPreferencesService>().evSourceType = valueListenable.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/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class MeteringScreenLayoutProvider extends StatefulWidget {
|
class MeteringScreenLayoutProvider extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
@ -18,12 +18,12 @@ class MeteringScreenLayoutProvider extends StatefulWidget {
|
||||||
|
|
||||||
class MeteringScreenLayoutProviderState extends State<MeteringScreenLayoutProvider> {
|
class MeteringScreenLayoutProviderState extends State<MeteringScreenLayoutProvider> {
|
||||||
late final MeteringScreenLayoutConfig _config =
|
late final MeteringScreenLayoutConfig _config =
|
||||||
context.read<UserPreferencesService>().meteringScreenLayout;
|
context.get<UserPreferencesService>().meteringScreenLayout;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MeteringScreenLayout(
|
return InheritedModelBase<MeteringScreenLayoutFeature, bool>(
|
||||||
config: MeteringScreenLayoutConfig.from(_config),
|
data: MeteringScreenLayoutConfig.from(_config),
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -38,45 +38,23 @@ class MeteringScreenLayoutProviderState extends State<MeteringScreenLayoutProvid
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
context.read<UserPreferencesService>().meteringScreenLayout = _config;
|
context.get<UserPreferencesService>().meteringScreenLayout = _config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MeteringScreenLayout extends InheritedModel<MeteringScreenLayoutFeature> {
|
typedef _MeteringScreenLayoutModel = InheritedModelBase<MeteringScreenLayoutFeature, bool>;
|
||||||
final MeteringScreenLayoutConfig config;
|
|
||||||
|
|
||||||
const MeteringScreenLayout({
|
|
||||||
required this.config,
|
|
||||||
required super.child,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
extension MeteringScreenLayout on InheritedModelBase<MeteringScreenLayoutFeature, bool> {
|
||||||
static MeteringScreenLayoutConfig of(BuildContext context, {bool listen = true}) {
|
static MeteringScreenLayoutConfig of(BuildContext context, {bool listen = true}) {
|
||||||
if (listen) {
|
if (listen) {
|
||||||
return context.dependOnInheritedWidgetOfExactType<MeteringScreenLayout>()!.config;
|
return context.dependOnInheritedWidgetOfExactType<_MeteringScreenLayoutModel>()!.data;
|
||||||
} else {
|
} else {
|
||||||
return context.findAncestorWidgetOfExactType<MeteringScreenLayout>()!.config;
|
return context.findAncestorWidgetOfExactType<_MeteringScreenLayoutModel>()!.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool featureStatusOf(BuildContext context, MeteringScreenLayoutFeature feature) {
|
static bool featureOf(BuildContext context, MeteringScreenLayoutFeature aspect) {
|
||||||
return InheritedModel.inheritFrom<MeteringScreenLayout>(context, aspect: feature)!
|
return InheritedModel.inheritFrom<_MeteringScreenLayoutModel>(context, aspect: aspect)!
|
||||||
.config[feature]!;
|
.data[aspect]!;
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotify(MeteringScreenLayout oldWidget) => true;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool updateShouldNotifyDependent(
|
|
||||||
MeteringScreenLayout oldWidget,
|
|
||||||
Set<MeteringScreenLayoutFeature> dependencies,
|
|
||||||
) {
|
|
||||||
for (final dependecy in dependencies) {
|
|
||||||
if (oldWidget.config[dependecy] != config[dependecy]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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:provider/provider.dart';
|
|
||||||
|
|
||||||
class StopTypeProvider extends StatefulWidget {
|
class StopTypeProvider extends StatefulWidget {
|
||||||
final Widget? child;
|
final Widget child;
|
||||||
|
|
||||||
const StopTypeProvider({this.child, super.key});
|
const StopTypeProvider({required this.child, super.key});
|
||||||
|
|
||||||
static StopTypeProviderState of(BuildContext context) {
|
static StopTypeProviderState of(BuildContext context) {
|
||||||
return context.findAncestorStateOfType<StopTypeProviderState>()!;
|
return context.findAncestorStateOfType<StopTypeProviderState>()!;
|
||||||
|
@ -28,8 +28,8 @@ class StopTypeProviderState extends State<StopTypeProvider> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Provider.value(
|
return InheritedWidgetBase<StopType>(
|
||||||
value: _stopType,
|
data: _stopType,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
import 'package:lightmeter/data/models/supported_locale.dart';
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class SupportedLocaleProvider extends StatefulWidget {
|
class SupportedLocaleProvider extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
@ -23,7 +23,7 @@ class SupportedLocaleProviderState extends State<SupportedLocaleProvider> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
valueListenable = ValueNotifier(context.read<UserPreferencesService>().locale);
|
valueListenable = ValueNotifier(context.get<UserPreferencesService>().locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -36,9 +36,9 @@ class SupportedLocaleProviderState extends State<SupportedLocaleProvider> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ValueListenableBuilder(
|
return ValueListenableBuilder(
|
||||||
valueListenable: valueListenable,
|
valueListenable: valueListenable,
|
||||||
builder: (_, value, child) => Provider.value(
|
builder: (_, value, child) => InheritedWidgetBase<SupportedLocale>(
|
||||||
value: value,
|
data: value,
|
||||||
child: child,
|
child: child!,
|
||||||
),
|
),
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
|
@ -47,7 +47,7 @@ class SupportedLocaleProviderState extends State<SupportedLocaleProvider> {
|
||||||
void setLocale(SupportedLocale locale) {
|
void setLocale(SupportedLocale locale) {
|
||||||
S.load(Locale(locale.intlName)).then((value) {
|
S.load(Locale(locale.intlName)).then((value) {
|
||||||
valueListenable.value = locale;
|
valueListenable.value = locale;
|
||||||
context.read<UserPreferencesService>().locale = locale;
|
context.get<UserPreferencesService>().locale = locale;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,14 @@ import 'package:lightmeter/data/models/dynamic_colors_state.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/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:material_color_utilities/material_color_utilities.dart';
|
import 'package:material_color_utilities/material_color_utilities.dart';
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class ThemeProvider extends StatefulWidget {
|
class ThemeProvider extends StatefulWidget {
|
||||||
final TransitionBuilder? builder;
|
final Widget child;
|
||||||
|
|
||||||
const ThemeProvider({
|
const ThemeProvider({
|
||||||
this.builder,
|
required this.child,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ class ThemeProvider extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserver {
|
class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserver {
|
||||||
UserPreferencesService get _prefs => context.read<UserPreferencesService>();
|
UserPreferencesService get _prefs => context.get<UserPreferencesService>();
|
||||||
|
|
||||||
late final _themeTypeNotifier = ValueNotifier<ThemeType>(_prefs.themeType);
|
late final _themeTypeNotifier = ValueNotifier<ThemeType>(_prefs.themeType);
|
||||||
late final _dynamicColorNotifier = ValueNotifier<bool>(_prefs.dynamicColor);
|
late final _dynamicColorNotifier = ValueNotifier<bool>(_prefs.dynamicColor);
|
||||||
|
@ -76,8 +75,8 @@ class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserve
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ValueListenableBuilder(
|
return ValueListenableBuilder(
|
||||||
valueListenable: _themeTypeNotifier,
|
valueListenable: _themeTypeNotifier,
|
||||||
builder: (_, themeType, __) => Provider.value(
|
builder: (_, themeType, __) => InheritedWidgetBase<ThemeType>(
|
||||||
value: themeType,
|
data: themeType,
|
||||||
child: ValueListenableBuilder(
|
child: ValueListenableBuilder(
|
||||||
valueListenable: _dynamicColorNotifier,
|
valueListenable: _dynamicColorNotifier,
|
||||||
builder: (_, useDynamicColor, __) => _DynamicColorProvider(
|
builder: (_, useDynamicColor, __) => _DynamicColorProvider(
|
||||||
|
@ -88,7 +87,7 @@ class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserve
|
||||||
builder: (_, primaryColor, __) => _ThemeDataProvider(
|
builder: (_, primaryColor, __) => _ThemeDataProvider(
|
||||||
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
primaryColor: dynamicPrimaryColor ?? primaryColor,
|
||||||
brightness: _themeBrightness,
|
brightness: _themeBrightness,
|
||||||
builder: widget.builder,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -154,8 +153,8 @@ class _DynamicColorProvider extends StatelessWidget {
|
||||||
dynamicPrimaryColor = null;
|
dynamicPrimaryColor = null;
|
||||||
state = DynamicColorState.unavailable;
|
state = DynamicColorState.unavailable;
|
||||||
}
|
}
|
||||||
return Provider.value(
|
return InheritedWidgetBase<DynamicColorState>(
|
||||||
value: state,
|
data: state,
|
||||||
child: builder(context, dynamicPrimaryColor),
|
child: builder(context, dynamicPrimaryColor),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -166,19 +165,19 @@ class _DynamicColorProvider extends StatelessWidget {
|
||||||
class _ThemeDataProvider extends StatelessWidget {
|
class _ThemeDataProvider extends StatelessWidget {
|
||||||
final Color primaryColor;
|
final Color primaryColor;
|
||||||
final Brightness brightness;
|
final Brightness brightness;
|
||||||
final TransitionBuilder? builder;
|
final Widget child;
|
||||||
|
|
||||||
const _ThemeDataProvider({
|
const _ThemeDataProvider({
|
||||||
required this.primaryColor,
|
required this.primaryColor,
|
||||||
required this.brightness,
|
required this.brightness,
|
||||||
required this.builder,
|
required this.child,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Provider.value(
|
return InheritedWidgetBase<ThemeData>(
|
||||||
value: _themeFromColorScheme(_colorSchemeFromColor()),
|
data: _themeFromColorScheme(_colorSchemeFromColor()),
|
||||||
builder: builder,
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
this.stopType,
|
this.stopType,
|
||||||
) : super(
|
) : super(
|
||||||
MeteringDataState(
|
MeteringDataState(
|
||||||
ev: 0.0,
|
ev: null,
|
||||||
film: _meteringInteractor.film,
|
film: _meteringInteractor.film,
|
||||||
iso: _meteringInteractor.iso,
|
iso: _meteringInteractor.iso,
|
||||||
nd: _meteringInteractor.ndFilter,
|
nd: _meteringInteractor.ndFilter,
|
||||||
|
@ -77,56 +77,76 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) {
|
void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) {
|
||||||
|
if (stopType != event.stopType) {
|
||||||
stopType = event.stopType;
|
stopType = event.stopType;
|
||||||
_updateMeasurements();
|
_updateMeasurements();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
|
void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
|
||||||
_equipmentProfileData = event.equipmentProfileData;
|
_equipmentProfileData = event.equipmentProfileData;
|
||||||
|
bool willUpdateMeasurements = false;
|
||||||
|
|
||||||
/// Update selected ISO value, if selected equipment profile
|
/// Update selected ISO value, if selected equipment profile
|
||||||
/// doesn't contain currently selected value
|
/// doesn't contain currently selected value
|
||||||
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
|
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
|
||||||
_meteringInteractor.iso = event.equipmentProfileData.isoValues.first;
|
_meteringInteractor.iso = event.equipmentProfileData.isoValues.first;
|
||||||
_iso = event.equipmentProfileData.isoValues.first;
|
_iso = event.equipmentProfileData.isoValues.first;
|
||||||
|
willUpdateMeasurements &= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The same for ND filter
|
/// The same for ND filter
|
||||||
if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) {
|
if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) {
|
||||||
_meteringInteractor.ndFilter = event.equipmentProfileData.ndValues.first;
|
_meteringInteractor.ndFilter = event.equipmentProfileData.ndValues.first;
|
||||||
_nd = event.equipmentProfileData.ndValues.first;
|
_nd = event.equipmentProfileData.ndValues.first;
|
||||||
|
willUpdateMeasurements &= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (willUpdateMeasurements) {
|
||||||
_updateMeasurements();
|
_updateMeasurements();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onFilmChanged(FilmChangedEvent event, Emitter emit) {
|
void _onFilmChanged(FilmChangedEvent event, Emitter emit) {
|
||||||
if (_iso.value != event.data.iso) {
|
if (_film.name != event.data.name) {
|
||||||
|
_film = event.data;
|
||||||
|
_meteringInteractor.film = event.data;
|
||||||
|
|
||||||
|
/// If user selects 'Other' film we preserve currently selected ISO
|
||||||
|
/// and therefore only discard reciprocity formula
|
||||||
|
if (_iso.value != event.data.iso && event.data != const Film.other()) {
|
||||||
final newIso = IsoValue.values.firstWhere(
|
final newIso = IsoValue.values.firstWhere(
|
||||||
(e) => e.value == event.data.iso,
|
(e) => e.value == event.data.iso,
|
||||||
orElse: () => _iso,
|
orElse: () => _iso,
|
||||||
);
|
);
|
||||||
add(IsoChangedEvent(newIso));
|
_meteringInteractor.iso = newIso;
|
||||||
|
_iso = newIso;
|
||||||
}
|
}
|
||||||
_film = event.data;
|
|
||||||
_meteringInteractor.film = event.data;
|
|
||||||
_updateMeasurements();
|
_updateMeasurements();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
|
void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
|
||||||
if (event.isoValue.value != _film.iso) {
|
/// Discard currently selected film even if ISO is the same,
|
||||||
|
/// because, for example, Fomapan 400 and any Ilford 400
|
||||||
|
/// have different reciprocity formulas
|
||||||
_film = Film.values.first;
|
_film = Film.values.first;
|
||||||
}
|
|
||||||
|
if (_iso != event.isoValue) {
|
||||||
_meteringInteractor.iso = event.isoValue;
|
_meteringInteractor.iso = event.isoValue;
|
||||||
_iso = event.isoValue;
|
_iso = event.isoValue;
|
||||||
_updateMeasurements();
|
_updateMeasurements();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onNdChanged(NdChangedEvent event, Emitter emit) {
|
void _onNdChanged(NdChangedEvent event, Emitter emit) {
|
||||||
|
if (_nd != event.ndValue) {
|
||||||
_meteringInteractor.ndFilter = event.ndValue;
|
_meteringInteractor.ndFilter = event.ndValue;
|
||||||
_nd = event.ndValue;
|
_nd = event.ndValue;
|
||||||
_updateMeasurements();
|
_updateMeasurements();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onMeasure(MeasureEvent _, Emitter emit) {
|
void _onMeasure(MeasureEvent _, Emitter emit) {
|
||||||
_meteringInteractor.quickVibration();
|
_meteringInteractor.quickVibration();
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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/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:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class MeteringBottomControls extends StatelessWidget {
|
class MeteringBottomControls extends StatelessWidget {
|
||||||
final double? ev;
|
final double? ev;
|
||||||
|
@ -44,7 +44,7 @@ class MeteringBottomControls extends StatelessWidget {
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
onPressed: onSwitchEvSourceType,
|
onPressed: onSwitchEvSourceType,
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
context.watch<EvSourceType>() != EvSourceType.camera
|
context.listen<EvSourceType>() != EvSourceType.camera
|
||||||
? Icons.camera_rear
|
? Icons.camera_rear
|
||||||
: Icons.wb_incandescent,
|
: Icons.wb_incandescent,
|
||||||
),
|
),
|
||||||
|
|
|
@ -6,6 +6,7 @@ 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/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:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class CameraContainerProvider extends StatelessWidget {
|
class CameraContainerProvider extends StatelessWidget {
|
||||||
|
@ -37,7 +38,7 @@ class CameraContainerProvider extends StatelessWidget {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => CameraContainerBloc(
|
create: (context) => CameraContainerBloc(
|
||||||
context.read<MeteringInteractor>(),
|
context.get<MeteringInteractor>(),
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
),
|
),
|
||||||
child: CameraContainer(
|
child: CameraContainer(
|
||||||
|
|
|
@ -56,14 +56,14 @@ class CameraContainer extends StatelessWidget {
|
||||||
topBarOverflow += Dimens.readingContainerSingleValueHeight;
|
topBarOverflow += Dimens.readingContainerSingleValueHeight;
|
||||||
topBarOverflow += Dimens.paddingS;
|
topBarOverflow += Dimens.paddingS;
|
||||||
}
|
}
|
||||||
if (MeteringScreenLayout.featureStatusOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs,
|
MeteringScreenLayoutFeature.extremeExposurePairs,
|
||||||
)) {
|
)) {
|
||||||
topBarOverflow += Dimens.readingContainerDoubleValueHeight;
|
topBarOverflow += Dimens.readingContainerDoubleValueHeight;
|
||||||
topBarOverflow += Dimens.paddingS;
|
topBarOverflow += Dimens.paddingS;
|
||||||
}
|
}
|
||||||
if (MeteringScreenLayout.featureStatusOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.filmPicker,
|
MeteringScreenLayoutFeature.filmPicker,
|
||||||
)) {
|
)) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ 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:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class LightSensorContainerProvider extends StatelessWidget {
|
class LightSensorContainerProvider extends StatelessWidget {
|
||||||
|
@ -37,7 +38,7 @@ class LightSensorContainerProvider extends StatelessWidget {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => LightSensorContainerBloc(
|
create: (context) => LightSensorContainerBloc(
|
||||||
context.read<MeteringInteractor>(),
|
context.get<MeteringInteractor>(),
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
),
|
),
|
||||||
child: LightSensorContainer(
|
child: LightSensorContainer(
|
||||||
|
|
|
@ -9,6 +9,7 @@ import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart';
|
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/reading_value_container/widget_container_reading_value.dart';
|
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/reading_value_container/widget_container_reading_value.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class ReadingsContainer extends StatelessWidget {
|
class ReadingsContainer extends StatelessWidget {
|
||||||
|
@ -42,7 +43,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
const _EquipmentProfilePicker(),
|
const _EquipmentProfilePicker(),
|
||||||
const _InnerPadding(),
|
const _InnerPadding(),
|
||||||
],
|
],
|
||||||
if (MeteringScreenLayout.featureStatusOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs,
|
MeteringScreenLayoutFeature.extremeExposurePairs,
|
||||||
)) ...[
|
)) ...[
|
||||||
|
@ -60,7 +61,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const _InnerPadding(),
|
const _InnerPadding(),
|
||||||
],
|
],
|
||||||
if (MeteringScreenLayout.featureStatusOf(
|
if (MeteringScreenLayout.featureOf(
|
||||||
context,
|
context,
|
||||||
MeteringScreenLayoutFeature.filmPicker,
|
MeteringScreenLayoutFeature.filmPicker,
|
||||||
)) ...[
|
)) ...[
|
||||||
|
@ -76,7 +77,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _IsoValuePicker(
|
child: _IsoValuePicker(
|
||||||
selectedValue: iso,
|
selectedValue: iso,
|
||||||
values: EquipmentProfile.of(context).isoValues,
|
values: context.listen<EquipmentProfile>().isoValues,
|
||||||
onChanged: onIsoChanged,
|
onChanged: onIsoChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -84,7 +85,7 @@ class ReadingsContainer extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _NdValuePicker(
|
child: _NdValuePicker(
|
||||||
selectedValue: nd,
|
selectedValue: nd,
|
||||||
values: EquipmentProfile.of(context).ndValues,
|
values: context.listen<EquipmentProfile>().ndValues,
|
||||||
onChanged: onNdChanged,
|
onChanged: onNdChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -107,16 +108,16 @@ class _EquipmentProfilePicker extends StatelessWidget {
|
||||||
return AnimatedDialogPicker<EquipmentProfileData>(
|
return AnimatedDialogPicker<EquipmentProfileData>(
|
||||||
icon: Icons.camera,
|
icon: Icons.camera,
|
||||||
title: S.of(context).equipmentProfile,
|
title: S.of(context).equipmentProfile,
|
||||||
selectedValue: EquipmentProfile.of(context),
|
selectedValue: context.listen<EquipmentProfile>(),
|
||||||
values: EquipmentProfiles.of(context),
|
values: context.listen<EquipmentProfiles>(),
|
||||||
itemTitleBuilder: (_, value) => Text(value.id.isEmpty ? S.of(context).none : value.name),
|
itemTitleBuilder: (_, value) => Text(value.id.isEmpty ? S.of(context).none : value.name),
|
||||||
onChanged: EquipmentProfileProvider.of(context).setProfile,
|
onChanged: EquipmentProfileProvider.of(context).setProfile,
|
||||||
closedChild: ReadingValueContainer.singleValue(
|
closedChild: ReadingValueContainer.singleValue(
|
||||||
value: ReadingValue(
|
value: ReadingValue(
|
||||||
label: S.of(context).equipmentProfile,
|
label: S.of(context).equipmentProfile,
|
||||||
value: EquipmentProfile.of(context).id.isEmpty
|
value: context.listen<EquipmentProfile>().id.isEmpty
|
||||||
? S.of(context).none
|
? S.of(context).none
|
||||||
: EquipmentProfile.of(context).name,
|
: context.listen<EquipmentProfile>().name,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,8 +10,8 @@ import 'package:lightmeter/providers/equipment_profile_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/screen_metering.dart';
|
import 'package:lightmeter/screens/metering/screen_metering.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class MeteringFlow extends StatefulWidget {
|
class MeteringFlow extends StatefulWidget {
|
||||||
const MeteringFlow({super.key});
|
const MeteringFlow({super.key});
|
||||||
|
@ -23,13 +23,13 @@ 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 Provider(
|
return InheritedWidgetBase<MeteringInteractor>(
|
||||||
create: (context) => MeteringInteractor(
|
data: MeteringInteractor(
|
||||||
context.read<UserPreferencesService>(),
|
context.get<UserPreferencesService>(),
|
||||||
context.read<CaffeineService>(),
|
context.get<CaffeineService>(),
|
||||||
context.read<HapticsService>(),
|
context.get<HapticsService>(),
|
||||||
context.read<PermissionsService>(),
|
context.get<PermissionsService>(),
|
||||||
context.read<LightSensorService>(),
|
context.get<LightSensorService>(),
|
||||||
),
|
),
|
||||||
child: MultiBlocProvider(
|
child: MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -37,9 +37,9 @@ class _MeteringFlowState extends State<MeteringFlow> {
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => MeteringBloc(
|
create: (context) => MeteringBloc(
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
context.read<MeteringInteractor>(),
|
context.get<MeteringInteractor>(),
|
||||||
EquipmentProfile.of(context, listen: false),
|
context.get<EquipmentProfile>(),
|
||||||
context.read<StopType>(),
|
context.get<StopType>(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -7,38 +7,22 @@ import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
import 'package:lightmeter/providers/ev_source_type_provider.dart';
|
import 'package:lightmeter/providers/ev_source_type_provider.dart';
|
||||||
import 'package:lightmeter/providers/metering_screen_layout_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:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class MeteringScreen extends StatefulWidget {
|
class MeteringScreen extends StatelessWidget {
|
||||||
const MeteringScreen({super.key});
|
const MeteringScreen({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
State<MeteringScreen> createState() => _MeteringScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MeteringScreenState extends State<MeteringScreen> {
|
|
||||||
MeteringBloc get _bloc => context.read<MeteringBloc>();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didChangeDependencies() {
|
|
||||||
super.didChangeDependencies();
|
|
||||||
_bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
|
|
||||||
_bloc.add(StopTypeChangedEvent(context.watch<StopType>()));
|
|
||||||
if (!MeteringScreenLayout.featureStatusOf(context, MeteringScreenLayoutFeature.filmPicker)) {
|
|
||||||
_bloc.add(const FilmChangedEvent(Film.other()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return _InheritedListeners(
|
||||||
|
child: Scaffold(
|
||||||
backgroundColor: Theme.of(context).colorScheme.background,
|
backgroundColor: Theme.of(context).colorScheme.background,
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -51,9 +35,10 @@ class _MeteringScreenState extends State<MeteringScreen> {
|
||||||
film: state.film,
|
film: state.film,
|
||||||
iso: state.iso,
|
iso: state.iso,
|
||||||
nd: state.nd,
|
nd: state.nd,
|
||||||
onFilmChanged: (value) => _bloc.add(FilmChangedEvent(value)),
|
onFilmChanged: (value) =>
|
||||||
onIsoChanged: (value) => _bloc.add(IsoChangedEvent(value)),
|
context.read<MeteringBloc>().add(FilmChangedEvent(value)),
|
||||||
onNdChanged: (value) => _bloc.add(NdChangedEvent(value)),
|
onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(value)),
|
||||||
|
onNdChanged: (value) => context.read<MeteringBloc>().add(NdChangedEvent(value)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -63,15 +48,43 @@ class _MeteringScreenState extends State<MeteringScreen> {
|
||||||
isMetering:
|
isMetering:
|
||||||
state is LoadingState || state is MeteringDataState && state.continuousMetering,
|
state is LoadingState || state is MeteringDataState && state.continuousMetering,
|
||||||
hasError: state is MeteringDataState && state.hasError,
|
hasError: state is MeteringDataState && state.hasError,
|
||||||
onSwitchEvSourceType: context.read<Environment>().hasLightSensor
|
onSwitchEvSourceType: context.get<Environment>().hasLightSensor
|
||||||
? EvSourceTypeProvider.of(context).toggleType
|
? EvSourceTypeProvider.of(context).toggleType
|
||||||
: null,
|
: null,
|
||||||
onMeasure: () => _bloc.add(const MeasureEvent()),
|
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
||||||
onSettings: () => Navigator.pushNamed(context, 'settings'),
|
onSettings: () => Navigator.pushNamed(context, 'settings'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InheritedListeners extends StatelessWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const _InheritedListeners({required this.child});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return InheritedWidgetListener<EquipmentProfile>(
|
||||||
|
onDidChangeDependencies: (value) {
|
||||||
|
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
||||||
|
},
|
||||||
|
child: InheritedWidgetListener<StopType>(
|
||||||
|
onDidChangeDependencies: (value) {
|
||||||
|
context.read<MeteringBloc>().add(StopTypeChangedEvent(value));
|
||||||
|
},
|
||||||
|
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
||||||
|
aspect: MeteringScreenLayoutFeature.filmPicker,
|
||||||
|
onDidChangeDependencies: (value) {
|
||||||
|
if (!value) context.read<MeteringBloc>().add(const FilmChangedEvent(Film.other()));
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +114,7 @@ class _MeteringContainerBuidler extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return context.watch<EvSourceType>() == EvSourceType.camera
|
return context.listen<EvSourceType>() == EvSourceType.camera
|
||||||
? CameraContainerProvider(
|
? CameraContainerProvider(
|
||||||
fastest: fastest,
|
fastest: fastest,
|
||||||
slowest: slowest,
|
slowest: slowest,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.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 +14,7 @@ class ReportIssueListTile extends StatelessWidget {
|
||||||
title: Text(S.of(context).reportIssue),
|
title: Text(S.of(context).reportIssue),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(
|
launchUrl(
|
||||||
Uri.parse(context.read<Environment>().issuesReportUrl),
|
Uri.parse(context.get<Environment>().issuesReportUrl),
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.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 +14,7 @@ class SourceCodeListTile extends StatelessWidget {
|
||||||
title: Text(S.of(context).sourceCode),
|
title: Text(S.of(context).sourceCode),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrl(
|
launchUrl(
|
||||||
Uri.parse(context.read<Environment>().sourceCodeUrl),
|
Uri.parse(context.get<Environment>().sourceCodeUrl),
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'package:clipboard/clipboard.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.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 +14,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.read<Environment>().contactEmail;
|
final email = context.get<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) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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';
|
||||||
|
|
||||||
class CaffeineListTileProvider extends StatelessWidget {
|
class CaffeineListTileProvider extends StatelessWidget {
|
||||||
const CaffeineListTileProvider({super.key});
|
const CaffeineListTileProvider({super.key});
|
||||||
|
@ -11,7 +12,7 @@ class CaffeineListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CaffeineListTileBloc(context.read<SettingsInteractor>()),
|
create: (context) => CaffeineListTileBloc(context.get<SettingsInteractor>()),
|
||||||
child: const CaffeineListTile(),
|
child: const CaffeineListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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';
|
||||||
|
|
||||||
class HapticsListTileProvider extends StatelessWidget {
|
class HapticsListTileProvider extends StatelessWidget {
|
||||||
const HapticsListTileProvider({super.key});
|
const HapticsListTileProvider({super.key});
|
||||||
|
@ -11,7 +12,7 @@ class HapticsListTileProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => HapticsListTileBloc(context.read<SettingsInteractor>()),
|
create: (context) => HapticsListTileBloc(context.get<SettingsInteractor>()),
|
||||||
child: const HapticsListTile(),
|
child: const HapticsListTile(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ 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/supported_locale_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:provider/provider.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,14 +13,14 @@ 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.watch<SupportedLocale>().localizedName),
|
trailing: Text(context.listen<SupportedLocale>().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.read<SupportedLocale>(),
|
selectedValue: context.get<SupportedLocale>(),
|
||||||
values: SupportedLocale.values,
|
values: SupportedLocale.values,
|
||||||
titleAdapter: (context, value) => value.localizedName,
|
titleAdapter: (context, value) => value.localizedName,
|
||||||
),
|
),
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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';
|
||||||
|
|
||||||
class CalibrationDialogProvider extends StatelessWidget {
|
class CalibrationDialogProvider extends StatelessWidget {
|
||||||
const CalibrationDialogProvider({super.key});
|
const CalibrationDialogProvider({super.key});
|
||||||
|
@ -11,7 +12,7 @@ class CalibrationDialogProvider extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CalibrationDialogBloc(context.read<SettingsInteractor>()),
|
create: (context) => CalibrationDialogBloc(context.get<SettingsInteractor>()),
|
||||||
child: const CalibrationDialog(),
|
child: const CalibrationDialog(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:lightmeter/screens/settings/components/metering/components/calib
|
||||||
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 {
|
||||||
|
@ -14,7 +15,7 @@ class CalibrationDialog extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final bool hasLightSensor = context.read<Environment>().hasLightSensor;
|
final bool hasLightSensor = context.get<Environment>().hasLightSensor;
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
icon: const Icon(Icons.settings_brightness),
|
icon: const Icon(Icons.settings_brightness),
|
||||||
titlePadding: Dimens.dialogIconTitlePadding,
|
titlePadding: Dimens.dialogIconTitlePadding,
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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/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:provider/provider.dart';
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class CalibrationListTile extends StatelessWidget {
|
class CalibrationListTile extends StatelessWidget {
|
||||||
const CalibrationListTile({super.key});
|
const CalibrationListTile({super.key});
|
||||||
|
@ -15,8 +15,8 @@ class CalibrationListTile extends StatelessWidget {
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showDialog<double>(
|
showDialog<double>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => Provider.value(
|
builder: (_) => InheritedWidgetBase(
|
||||||
value: context.read<SettingsInteractor>(),
|
data: context.get<SettingsInteractor>(),
|
||||||
child: const CalibrationDialogProvider(),
|
child: const CalibrationDialogProvider(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,6 +5,7 @@ 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 {
|
||||||
|
@ -18,12 +19,13 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
static const maxProfiles = 5 + 1; // replace with a constant from iap
|
static const maxProfiles = 5 + 1; // replace with a constant from iap
|
||||||
|
|
||||||
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
|
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
|
||||||
int get profilesCount => EquipmentProfiles.of(context).length;
|
int get profilesCount => context.listen<EquipmentProfiles>().length;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
profileContainersKeys = EquipmentProfiles.of(context, listen: false)
|
profileContainersKeys = context
|
||||||
|
.get<EquipmentProfiles>()
|
||||||
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
|
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
),
|
),
|
||||||
child: EquipmentProfileContainer(
|
child: EquipmentProfileContainer(
|
||||||
key: profileContainersKeys[index],
|
key: profileContainersKeys[index],
|
||||||
data: EquipmentProfiles.of(context)[index],
|
data: context.listen<EquipmentProfiles>()[index],
|
||||||
onExpand: () => _keepExpandedAt(index),
|
onExpand: () => _keepExpandedAt(index),
|
||||||
onUpdate: (profileData) => _updateProfileAt(profileData, index),
|
onUpdate: (profileData) => _updateProfileAt(profileData, index),
|
||||||
onDelete: () => _removeProfileAt(index),
|
onDelete: () => _removeProfileAt(index),
|
||||||
|
@ -87,7 +89,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _removeProfileAt(int index) {
|
void _removeProfileAt(int index) {
|
||||||
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]);
|
EquipmentProfileProvider.of(context).deleteProfile(context.listen<EquipmentProfiles>()[index]);
|
||||||
profileContainersKeys.removeAt(index);
|
profileContainersKeys.removeAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ 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/stop_type_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';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class StopTypeListTile extends StatelessWidget {
|
class StopTypeListTile extends StatelessWidget {
|
||||||
const StopTypeListTile({super.key});
|
const StopTypeListTile({super.key});
|
||||||
|
@ -13,14 +13,14 @@ 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.watch<StopType>())),
|
trailing: Text(_typeToString(context, context.listen<StopType>())),
|
||||||
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.read<StopType>(),
|
selectedValue: context.get<StopType>(),
|
||||||
values: StopType.values,
|
values: StopType.values,
|
||||||
titleAdapter: _typeToString,
|
titleAdapter: _typeToString,
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/theme_provider.dart';
|
||||||
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||||
|
|
||||||
class DynamicColorListTile extends StatelessWidget {
|
class DynamicColorListTile extends StatelessWidget {
|
||||||
const DynamicColorListTile({super.key});
|
const DynamicColorListTile({super.key});
|
||||||
|
@ -12,7 +12,7 @@ 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.watch<DynamicColorState>() == DynamicColorState.enabled,
|
value: context.listen<DynamicColorState>() == DynamicColorState.enabled,
|
||||||
onChanged: ThemeProvider.of(context).enableDynamicColor,
|
onChanged: ThemeProvider.of(context).enableDynamicColor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/theme_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.watch<DynamicColorState>() == DynamicColorState.enabled) {
|
if (context.listen<DynamicColorState>() == DynamicColorState.enabled) {
|
||||||
return Opacity(
|
return Opacity(
|
||||||
opacity: Dimens.disabledOpacity,
|
opacity: Dimens.disabledOpacity,
|
||||||
child: IgnorePointer(
|
child: IgnorePointer(
|
||||||
|
|
|
@ -3,7 +3,7 @@ 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/theme_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:provider/provider.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,14 +13,14 @@ 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.watch<ThemeType>())),
|
trailing: Text(_typeToString(context, context.listen<ThemeType>())),
|
||||||
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.read<ThemeType>(),
|
selectedValue: context.get<ThemeType>(),
|
||||||
values: ThemeType.values,
|
values: ThemeType.values,
|
||||||
titleAdapter: _typeToString,
|
titleAdapter: _typeToString,
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/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});
|
||||||
|
@ -18,7 +17,7 @@ class ThemeSettingsSection extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
const ThemeTypeListTile(),
|
const ThemeTypeListTile(),
|
||||||
const PrimaryColorListTile(),
|
const PrimaryColorListTile(),
|
||||||
if (context.read<DynamicColorState>() != DynamicColorState.unavailable)
|
if (context.get<DynamicColorState>() != DynamicColorState.unavailable)
|
||||||
const DynamicColorListTile(),
|
const DynamicColorListTile(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,18 +4,18 @@ import 'package:lightmeter/data/haptics_service.dart';
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:lightmeter/interactors/settings_interactor.dart';
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
import 'package:lightmeter/screens/settings/screen_settings.dart';
|
import 'package:lightmeter/screens/settings/screen_settings.dart';
|
||||||
import 'package:provider/provider.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 Provider(
|
return InheritedWidgetBase<SettingsInteractor>(
|
||||||
create: (context) => SettingsInteractor(
|
data: SettingsInteractor(
|
||||||
context.read<UserPreferencesService>(),
|
context.get<UserPreferencesService>(),
|
||||||
context.read<CaffeineService>(),
|
context.get<CaffeineService>(),
|
||||||
context.read<HapticsService>(),
|
context.get<HapticsService>(),
|
||||||
),
|
),
|
||||||
child: const SettingsScreen(),
|
child: const SettingsScreen(),
|
||||||
);
|
);
|
||||||
|
|
171
lib/utils/inherited_generics.dart
Normal file
171
lib/utils/inherited_generics.dart
Normal file
|
@ -0,0 +1,171 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
/// Listening to multiple dependencies at the same time causes firing an event for all dependencies
|
||||||
|
/// even though some of them didn't change:
|
||||||
|
/// ```dart
|
||||||
|
/// @override
|
||||||
|
/// void didChangeDependencies() {
|
||||||
|
/// super.didChangeDependencies();
|
||||||
|
/// _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
|
||||||
|
/// if (!MeteringScreenLayout.featureStatusOf(context, MeteringScreenLayoutFeature.filmPicker)) {
|
||||||
|
/// _bloc.add(const FilmChangedEvent(Film.other()));
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
/// To overcome this issue I've decided to create a generic listener,
|
||||||
|
/// that will listen to each dependency separately.
|
||||||
|
class InheritedWidgetListener<T> extends StatefulWidget {
|
||||||
|
final ValueChanged<T> onDidChangeDependencies;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const InheritedWidgetListener({
|
||||||
|
required this.onDidChangeDependencies,
|
||||||
|
required this.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<InheritedWidgetListener<T>> createState() => _InheritedWidgetListenerState<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InheritedWidgetListenerState<T> extends State<InheritedWidgetListener<T>> {
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
widget.onDidChangeDependencies(context.listen<T>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return widget.child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritedWidgetBase<T> extends InheritedWidget {
|
||||||
|
final T data;
|
||||||
|
|
||||||
|
const InheritedWidgetBase({
|
||||||
|
required this.data,
|
||||||
|
required super.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static T of<T>(BuildContext context, {bool listen = true}) {
|
||||||
|
if (listen) {
|
||||||
|
return context.dependOnInheritedWidgetOfExactType<InheritedWidgetBase<T>>()!.data;
|
||||||
|
} else {
|
||||||
|
return context.findAncestorWidgetOfExactType<InheritedWidgetBase<T>>()!.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(InheritedWidgetBase<T> oldWidget) => true;
|
||||||
|
}
|
||||||
|
|
||||||
|
extension InheritedWidgetBaseContext on BuildContext {
|
||||||
|
T get<T>() {
|
||||||
|
return InheritedWidgetBase.of<T>(this, listen: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
T listen<T>() {
|
||||||
|
return InheritedWidgetBase.of<T>(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Listening to multiple dependencies at the same time causes firing an event for all dependencies
|
||||||
|
/// even though some of them didn't change:
|
||||||
|
/// ```dart
|
||||||
|
/// @override
|
||||||
|
/// void didChangeDependencies() {
|
||||||
|
/// super.didChangeDependencies();
|
||||||
|
/// _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
|
||||||
|
/// if (!MeteringScreenLayout.featureStatusOf(context, MeteringScreenLayoutFeature.filmPicker)) {
|
||||||
|
/// _bloc.add(const FilmChangedEvent(Film.other()));
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
/// To overcome this issue I've decided to create a generic listener,
|
||||||
|
/// that will listen to each dependency separately.
|
||||||
|
class InheritedModelAspectListener<A extends Object, T> extends StatefulWidget {
|
||||||
|
final A aspect;
|
||||||
|
final ValueChanged<T> onDidChangeDependencies;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const InheritedModelAspectListener({
|
||||||
|
required this.aspect,
|
||||||
|
required this.onDidChangeDependencies,
|
||||||
|
required this.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<InheritedModelAspectListener<A, T>> createState() =>
|
||||||
|
_InheritedModelAspectListenerState<A, T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InheritedModelAspectListenerState<A extends Object, T>
|
||||||
|
extends State<InheritedModelAspectListener<A, T>> {
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
widget.onDidChangeDependencies(context.listenModelFeature<A, T>(widget.aspect));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return widget.child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritedModelBase<A, T> extends InheritedModel<A> {
|
||||||
|
final Map<A, T> data;
|
||||||
|
|
||||||
|
const InheritedModelBase({
|
||||||
|
required this.data,
|
||||||
|
required super.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static Map<A, T> of<A, T>(BuildContext context, {bool listen = true}) {
|
||||||
|
if (listen) {
|
||||||
|
return context.dependOnInheritedWidgetOfExactType<InheritedModelBase<A, T>>()!.data;
|
||||||
|
} else {
|
||||||
|
return context.findAncestorWidgetOfExactType<InheritedModelBase<A, T>>()!.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static T featureOf<A extends Object, T>(BuildContext context, A aspect) {
|
||||||
|
return InheritedModel.inheritFrom<InheritedModelBase<A, T>>(context, aspect: aspect)!
|
||||||
|
.data[aspect]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(InheritedModelBase oldWidget) => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotifyDependent(
|
||||||
|
InheritedModelBase<A, T> oldWidget,
|
||||||
|
Set<A> dependencies,
|
||||||
|
) {
|
||||||
|
for (final dependecy in dependencies) {
|
||||||
|
if (oldWidget.data[dependecy] != data[dependecy]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension InheritedModelBaseContext on BuildContext {
|
||||||
|
Map<A, T> getModel<A, T>() {
|
||||||
|
return InheritedModelBase.of<A, T>(this, listen: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<A, T> listenModel<A, T>() {
|
||||||
|
return InheritedModelBase.of<A, T>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
T listenModelFeature<A extends Object, T>(A aspect) {
|
||||||
|
return InheritedModelBase.featureOf<A, T>(this, aspect);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,6 @@ dependencies:
|
||||||
material_color_utilities: 0.2.0
|
material_color_utilities: 0.2.0
|
||||||
package_info_plus: 4.0.1
|
package_info_plus: 4.0.1
|
||||||
permission_handler: 10.2.0
|
permission_handler: 10.2.0
|
||||||
provider: 6.0.4
|
|
||||||
shared_preferences: 2.1.1
|
shared_preferences: 2.1.1
|
||||||
url_launcher: 6.1.11
|
url_launcher: 6.1.11
|
||||||
uuid: 3.0.7
|
uuid: 3.0.7
|
||||||
|
|
Loading…
Reference in a new issue