mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
implemented MeteringScreenLayoutProvider
This commit is contained in:
parent
be0617a99c
commit
12d44d6bab
2 changed files with 102 additions and 24 deletions
|
@ -18,6 +18,7 @@ import 'environment.dart';
|
||||||
import 'generated/l10n.dart';
|
import 'generated/l10n.dart';
|
||||||
import 'providers/equipment_profile_provider.dart';
|
import 'providers/equipment_profile_provider.dart';
|
||||||
import 'providers/ev_source_type_provider.dart';
|
import 'providers/ev_source_type_provider.dart';
|
||||||
|
import 'providers/features_provider.dart';
|
||||||
import 'providers/theme_provider.dart';
|
import 'providers/theme_provider.dart';
|
||||||
import 'screens/metering/flow_metering.dart';
|
import 'screens/metering/flow_metering.dart';
|
||||||
import 'screens/settings/flow_settings.dart';
|
import 'screens/settings/flow_settings.dart';
|
||||||
|
@ -47,6 +48,7 @@ class Application extends StatelessWidget {
|
||||||
Provider(create: (_) => PermissionsService()),
|
Provider(create: (_) => PermissionsService()),
|
||||||
Provider(create: (_) => const LightSensorService()),
|
Provider(create: (_) => const LightSensorService()),
|
||||||
],
|
],
|
||||||
|
child: MeteringScreenLayoutProvider(
|
||||||
child: StopTypeProvider(
|
child: StopTypeProvider(
|
||||||
child: EquipmentProfileProvider(
|
child: EquipmentProfileProvider(
|
||||||
child: EvSourceTypeProvider(
|
child: EvSourceTypeProvider(
|
||||||
|
@ -79,6 +81,7 @@ class Application extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
|
|
75
lib/providers/features_provider.dart
Normal file
75
lib/providers/features_provider.dart
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
enum MeteringScreenLayoutFeature { extremeExposurePairs, reciprocity }
|
||||||
|
|
||||||
|
class MeteringScreenLayoutProvider extends StatefulWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const MeteringScreenLayoutProvider({required this.child, super.key});
|
||||||
|
|
||||||
|
static MeteringScreenLayoutProviderState of(BuildContext context) {
|
||||||
|
return context.findAncestorStateOfType<MeteringScreenLayoutProviderState>()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MeteringScreenLayoutProvider> createState() => MeteringScreenLayoutProviderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class MeteringScreenLayoutProviderState extends State<MeteringScreenLayoutProvider> {
|
||||||
|
final Map<MeteringScreenLayoutFeature, bool> _features = {
|
||||||
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
|
MeteringScreenLayoutFeature.reciprocity: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MeteringScreenLayout(
|
||||||
|
features: _features,
|
||||||
|
child: widget.child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFeature(MeteringScreenLayoutFeature feature, {required bool enabled}) {
|
||||||
|
setState(() {
|
||||||
|
_features.update(
|
||||||
|
feature,
|
||||||
|
(_) => enabled,
|
||||||
|
ifAbsent: () => enabled,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MeteringScreenLayout extends InheritedModel<MeteringScreenLayoutFeature> {
|
||||||
|
final Map<MeteringScreenLayoutFeature, bool> features;
|
||||||
|
|
||||||
|
const MeteringScreenLayout({
|
||||||
|
required this.features,
|
||||||
|
required super.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static bool of(BuildContext context, MeteringScreenLayoutFeature feature, {bool listen = true}) {
|
||||||
|
if (listen) {
|
||||||
|
return context.dependOnInheritedWidgetOfExactType<MeteringScreenLayout>()!.features[feature]!;
|
||||||
|
} else {
|
||||||
|
return context.findAncestorWidgetOfExactType<MeteringScreenLayout>()!.features[feature]!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(MeteringScreenLayout oldWidget) => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotifyDependent(
|
||||||
|
MeteringScreenLayout oldWidget,
|
||||||
|
Set<MeteringScreenLayoutFeature> dependencies,
|
||||||
|
) {
|
||||||
|
for (final dependecy in dependencies) {
|
||||||
|
if (oldWidget.features[dependecy] != features[dependecy]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue