mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
Removed Inherited Generics
This commit is contained in:
parent
a9102d4e7d
commit
28c72d492f
16 changed files with 156 additions and 147 deletions
|
@ -1,12 +1,9 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.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';
|
||||||
|
|
||||||
// TODO(@vodemn): This will be removed in #89
|
// TODO(@vodemn): This will be removed in #89
|
||||||
typedef EquipmentProfiles = List<EquipmentProfile>;
|
|
||||||
|
|
||||||
class EquipmentProfileProvider extends StatefulWidget {
|
class EquipmentProfileProvider extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
|
@ -51,12 +48,10 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
|
|
||||||
@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,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,3 +96,42 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -9,7 +9,6 @@ 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 {
|
||||||
|
@ -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,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,6 @@ 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});
|
||||||
|
@ -18,7 +17,7 @@ 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(
|
||||||
ServicesProvider.userPreferencesServiceOf(context),
|
ServicesProvider.userPreferencesServiceOf(context),
|
||||||
ServicesProvider.caffeineServiceOf(context),
|
ServicesProvider.caffeineServiceOf(context),
|
||||||
|
@ -27,22 +26,36 @@ class _MeteringFlowState extends State<MeteringFlow> {
|
||||||
ServicesProvider.lightSensorServiceOf(context),
|
ServicesProvider.lightSensorServiceOf(context),
|
||||||
ServicesProvider.volumeEventsServiceOf(context),
|
ServicesProvider.volumeEventsServiceOf(context),
|
||||||
)..initialize(),
|
)..initialize(),
|
||||||
child: InheritedWidgetBase<VolumeKeysNotifier>(
|
|
||||||
data: VolumeKeysNotifier(ServicesProvider.volumeEventsServiceOf(context)),
|
|
||||||
child: MultiBlocProvider(
|
child: MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(create: (_) => MeteringCommunicationBloc()),
|
BlocProvider(create: (_) => MeteringCommunicationBloc()),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => MeteringBloc(
|
create: (context) => MeteringBloc(
|
||||||
context.get<MeteringInteractor>(),
|
MeteringInteractorProvider.of(context),
|
||||||
context.get<VolumeKeysNotifier>(),
|
VolumeKeysNotifier(ServicesProvider.volumeEventsServiceOf(context)),
|
||||||
context.read<MeteringCommunicationBloc>(),
|
context.read<MeteringCommunicationBloc>(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: const MeteringScreen(),
|
child: const MeteringScreen(),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MeteringInteractorProvider extends InheritedWidget {
|
||||||
|
final MeteringInteractor data;
|
||||||
|
|
||||||
|
const MeteringInteractorProvider({
|
||||||
|
required this.data,
|
||||||
|
required super.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static MeteringInteractor of(BuildContext context) {
|
||||||
|
return context.findAncestorWidgetOfExactType<MeteringInteractorProvider>()!.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(MeteringInteractorProvider oldWidget) => false;
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:lightmeter/data/models/ev_source_type.dart';
|
||||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||||
import 'package:lightmeter/data/models/film.dart';
|
import 'package:lightmeter/data/models/film.dart';
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_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';
|
||||||
|
@ -15,7 +16,7 @@ import 'package:lightmeter/screens/metering/components/light_sensor_container/pr
|
||||||
import 'package:lightmeter/screens/metering/event_metering.dart';
|
import 'package:lightmeter/screens/metering/event_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/state_metering.dart';
|
import 'package:lightmeter/screens/metering/state_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/utils/listener_metering_layout_feature.dart';
|
import 'package:lightmeter/screens/metering/utils/listener_metering_layout_feature.dart';
|
||||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
import 'package:lightmeter/screens/metering/utils/listsner_equipment_profiles.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class MeteringScreen extends StatelessWidget {
|
class MeteringScreen extends StatelessWidget {
|
||||||
|
@ -72,7 +73,7 @@ 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));
|
||||||
},
|
},
|
||||||
|
@ -146,7 +147,7 @@ class _MeteringContainerBuidler extends StatelessWidget {
|
||||||
final StopType stopType = UserPreferencesProvider.stopTypeOf(context);
|
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 =
|
||||||
|
|
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,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,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,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) {
|
||||||
|
|
|
@ -2,14 +2,13 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/interactors/settings_interactor.dart';
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
import 'package:lightmeter/providers/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(
|
||||||
ServicesProvider.userPreferencesServiceOf(context),
|
ServicesProvider.userPreferencesServiceOf(context),
|
||||||
ServicesProvider.caffeineServiceOf(context),
|
ServicesProvider.caffeineServiceOf(context),
|
||||||
|
@ -20,3 +19,20 @@ class SettingsFlow extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,73 +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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue