diff --git a/lib/main.dart b/lib/main.dart index 31aff18..4d46f1f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'models/photography_value.dart'; import 'res/theme.dart'; import 'screens/metering/metering_bloc.dart'; import 'screens/metering/metering_screen.dart'; +import 'utils/stop_type_provider.dart'; void main() { runApp(const MyApp()); @@ -15,15 +16,17 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => MeteringBloc(Stop.third), - child: MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - useMaterial3: true, - colorScheme: lightColorScheme, + return StopTypeProvider( + child: BlocProvider( + create: (context) => MeteringBloc(context.read()), + child: MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + useMaterial3: true, + colorScheme: lightColorScheme, + ), + home: const MeteringScreen(), ), - home: const MeteringScreen(), ), ); } diff --git a/lib/models/aperture_value.dart b/lib/models/aperture_value.dart index 608fdb2..996c081 100644 --- a/lib/models/aperture_value.dart +++ b/lib/models/aperture_value.dart @@ -19,49 +19,49 @@ class ApertureValue extends PhotographyValue { } const List apertureValues = [ - ApertureValue(1.0, Stop.full), - ApertureValue(1.1, Stop.third), - ApertureValue(1.2, Stop.half), - ApertureValue(1.2, Stop.third), - ApertureValue(1.4, Stop.full), - ApertureValue(1.6, Stop.third), - ApertureValue(1.7, Stop.half), - ApertureValue(1.8, Stop.third), - ApertureValue(2.0, Stop.full), - ApertureValue(2.2, Stop.third), - ApertureValue(2.4, Stop.half), - ApertureValue(2.4, Stop.third), - ApertureValue(2.8, Stop.full), - ApertureValue(3.2, Stop.third), - ApertureValue(3.3, Stop.half), - ApertureValue(3.5, Stop.third), - ApertureValue(4.0, Stop.full), - ApertureValue(4.5, Stop.third), - ApertureValue(4.8, Stop.half), - ApertureValue(5.0, Stop.third), - ApertureValue(5.6, Stop.full), - ApertureValue(6.3, Stop.third), - ApertureValue(6.7, Stop.half), - ApertureValue(7.1, Stop.third), - ApertureValue(8, Stop.full), - ApertureValue(9, Stop.third), - ApertureValue(9.5, Stop.half), - ApertureValue(10, Stop.third), - ApertureValue(11, Stop.full), - ApertureValue(13, Stop.third), - ApertureValue(13, Stop.half), - ApertureValue(14, Stop.third), - ApertureValue(16, Stop.full), - ApertureValue(18, Stop.third), - ApertureValue(19, Stop.half), - ApertureValue(20, Stop.third), - ApertureValue(22, Stop.full), - ApertureValue(25, Stop.third), - ApertureValue(27, Stop.half), - ApertureValue(29, Stop.third), - ApertureValue(32, Stop.full), - ApertureValue(36, Stop.third), - ApertureValue(38, Stop.half), - ApertureValue(42, Stop.third), - ApertureValue(45, Stop.full), + ApertureValue(1.0, StopType.full), + ApertureValue(1.1, StopType.third), + ApertureValue(1.2, StopType.half), + ApertureValue(1.2, StopType.third), + ApertureValue(1.4, StopType.full), + ApertureValue(1.6, StopType.third), + ApertureValue(1.7, StopType.half), + ApertureValue(1.8, StopType.third), + ApertureValue(2.0, StopType.full), + ApertureValue(2.2, StopType.third), + ApertureValue(2.4, StopType.half), + ApertureValue(2.4, StopType.third), + ApertureValue(2.8, StopType.full), + ApertureValue(3.2, StopType.third), + ApertureValue(3.3, StopType.half), + ApertureValue(3.5, StopType.third), + ApertureValue(4.0, StopType.full), + ApertureValue(4.5, StopType.third), + ApertureValue(4.8, StopType.half), + ApertureValue(5.0, StopType.third), + ApertureValue(5.6, StopType.full), + ApertureValue(6.3, StopType.third), + ApertureValue(6.7, StopType.half), + ApertureValue(7.1, StopType.third), + ApertureValue(8, StopType.full), + ApertureValue(9, StopType.third), + ApertureValue(9.5, StopType.half), + ApertureValue(10, StopType.third), + ApertureValue(11, StopType.full), + ApertureValue(13, StopType.third), + ApertureValue(13, StopType.half), + ApertureValue(14, StopType.third), + ApertureValue(16, StopType.full), + ApertureValue(18, StopType.third), + ApertureValue(19, StopType.half), + ApertureValue(20, StopType.third), + ApertureValue(22, StopType.full), + ApertureValue(25, StopType.third), + ApertureValue(27, StopType.half), + ApertureValue(29, StopType.third), + ApertureValue(32, StopType.full), + ApertureValue(36, StopType.third), + ApertureValue(38, StopType.half), + ApertureValue(42, StopType.third), + ApertureValue(45, StopType.full), ]; diff --git a/lib/models/iso_value.dart b/lib/models/iso_value.dart index 03849cc..6cef3cf 100644 --- a/lib/models/iso_value.dart +++ b/lib/models/iso_value.dart @@ -11,38 +11,38 @@ class IsoValue extends PhotographyValue { } const List isoValues = [ - IsoValue(3, Stop.full), - IsoValue(4, Stop.third), - IsoValue(5, Stop.third), - IsoValue(6, Stop.full), - IsoValue(8, Stop.third), - IsoValue(10, Stop.third), - IsoValue(12, Stop.full), - IsoValue(16, Stop.third), - IsoValue(20, Stop.third), - IsoValue(25, Stop.full), - IsoValue(32, Stop.third), - IsoValue(40, Stop.third), - IsoValue(50, Stop.full), - IsoValue(64, Stop.third), - IsoValue(80, Stop.third), - IsoValue(100, Stop.full), - IsoValue(125, Stop.third), - IsoValue(160, Stop.third), - IsoValue(200, Stop.full), - IsoValue(250, Stop.third), - IsoValue(320, Stop.third), - IsoValue(400, Stop.full), - IsoValue(500, Stop.third), - IsoValue(640, Stop.third), - IsoValue(800, Stop.full), - IsoValue(1000, Stop.third), - IsoValue(1250, Stop.third), - IsoValue(1600, Stop.full), - IsoValue(2000, Stop.third), - IsoValue(2500, Stop.third), - IsoValue(3200, Stop.full), - IsoValue(4000, Stop.third), - IsoValue(5000, Stop.third), - IsoValue(6400, Stop.full), + IsoValue(3, StopType.full), + IsoValue(4, StopType.third), + IsoValue(5, StopType.third), + IsoValue(6, StopType.full), + IsoValue(8, StopType.third), + IsoValue(10, StopType.third), + IsoValue(12, StopType.full), + IsoValue(16, StopType.third), + IsoValue(20, StopType.third), + IsoValue(25, StopType.full), + IsoValue(32, StopType.third), + IsoValue(40, StopType.third), + IsoValue(50, StopType.full), + IsoValue(64, StopType.third), + IsoValue(80, StopType.third), + IsoValue(100, StopType.full), + IsoValue(125, StopType.third), + IsoValue(160, StopType.third), + IsoValue(200, StopType.full), + IsoValue(250, StopType.third), + IsoValue(320, StopType.third), + IsoValue(400, StopType.full), + IsoValue(500, StopType.third), + IsoValue(640, StopType.third), + IsoValue(800, StopType.full), + IsoValue(1000, StopType.third), + IsoValue(1250, StopType.third), + IsoValue(1600, StopType.full), + IsoValue(2000, StopType.third), + IsoValue(2500, StopType.third), + IsoValue(3200, StopType.full), + IsoValue(4000, StopType.third), + IsoValue(5000, StopType.third), + IsoValue(6400, StopType.full), ]; diff --git a/lib/models/photography_value.dart b/lib/models/photography_value.dart index f800255..a881dc4 100644 --- a/lib/models/photography_value.dart +++ b/lib/models/photography_value.dart @@ -2,11 +2,11 @@ part 'aperture_value.dart'; part 'iso_value.dart'; part 'shutter_speed_value.dart'; -enum Stop { full, half, third } +enum StopType { full, half, third } abstract class PhotographyValue { final T rawValue; - final Stop stopType; + final StopType stopType; const PhotographyValue(this.rawValue, this.stopType); @@ -14,20 +14,20 @@ abstract class PhotographyValue { } extension PhotographyValues on List { - List whereStopType(Stop stopType) { + List whereStopType(StopType stopType) { switch (stopType) { - case Stop.full: - return where((e) => e.stopType == Stop.full).toList(); - case Stop.half: - return where((e) => e.stopType == Stop.full || e.stopType == Stop.half).toList(); - case Stop.third: - return where((e) => e.stopType == Stop.full || e.stopType == Stop.third).toList(); + case StopType.full: + return where((e) => e.stopType == StopType.full).toList(); + case StopType.half: + return where((e) => e.stopType == StopType.full || e.stopType == StopType.half).toList(); + case StopType.third: + return where((e) => e.stopType == StopType.full || e.stopType == StopType.third).toList(); } } - List fullStops() => whereStopType(Stop.full); + List fullStops() => whereStopType(StopType.full); - List halfStops() => whereStopType(Stop.half); + List halfStops() => whereStopType(StopType.half); - List thirdStops() => whereStopType(Stop.third); + List thirdStops() => whereStopType(StopType.third); } diff --git a/lib/models/shutter_speed_value.dart b/lib/models/shutter_speed_value.dart index 9272c05..d330d45 100644 --- a/lib/models/shutter_speed_value.dart +++ b/lib/models/shutter_speed_value.dart @@ -23,65 +23,65 @@ class ShutterSpeedValue extends PhotographyValue { } const List shutterSpeedValues = [ - ShutterSpeedValue(2000, true, Stop.full), - ShutterSpeedValue(1600, true, Stop.third), - ShutterSpeedValue(1500, true, Stop.half), - ShutterSpeedValue(1250, true, Stop.third), - ShutterSpeedValue(1000, true, Stop.full), - ShutterSpeedValue(800, true, Stop.third), - ShutterSpeedValue(750, true, Stop.half), - ShutterSpeedValue(640, true, Stop.third), - ShutterSpeedValue(500, true, Stop.full), - ShutterSpeedValue(400, true, Stop.third), - ShutterSpeedValue(350, true, Stop.half), - ShutterSpeedValue(320, true, Stop.third), - ShutterSpeedValue(250, true, Stop.full), - ShutterSpeedValue(200, true, Stop.third), - ShutterSpeedValue(180, true, Stop.half), - ShutterSpeedValue(160, true, Stop.third), - ShutterSpeedValue(125, true, Stop.full), - ShutterSpeedValue(100, true, Stop.third), - ShutterSpeedValue(90, true, Stop.half), - ShutterSpeedValue(80, true, Stop.third), - ShutterSpeedValue(60, true, Stop.full), - ShutterSpeedValue(50, true, Stop.third), - ShutterSpeedValue(45, true, Stop.half), - ShutterSpeedValue(40, true, Stop.third), - ShutterSpeedValue(30, true, Stop.full), - ShutterSpeedValue(25, true, Stop.third), - ShutterSpeedValue(20, true, Stop.half), - ShutterSpeedValue(20, true, Stop.third), - ShutterSpeedValue(15, true, Stop.full), - ShutterSpeedValue(13, true, Stop.third), - ShutterSpeedValue(10, true, Stop.half), - ShutterSpeedValue(10, true, Stop.third), - ShutterSpeedValue(8, true, Stop.full), - ShutterSpeedValue(6, true, Stop.third), - ShutterSpeedValue(6, true, Stop.half), - ShutterSpeedValue(5, true, Stop.third), - ShutterSpeedValue(4, true, Stop.full), - ShutterSpeedValue(3, true, Stop.third), - ShutterSpeedValue(3, true, Stop.half), - ShutterSpeedValue(2.5, true, Stop.third), - ShutterSpeedValue(2, true, Stop.full), - ShutterSpeedValue(1.6, true, Stop.third), - ShutterSpeedValue(1.5, true, Stop.half), - ShutterSpeedValue(1.3, true, Stop.third), - ShutterSpeedValue(1, false, Stop.full), - ShutterSpeedValue(1.3, false, Stop.third), - ShutterSpeedValue(1.5, false, Stop.half), - ShutterSpeedValue(1.6, false, Stop.third), - ShutterSpeedValue(2, false, Stop.full), - ShutterSpeedValue(2.5, false, Stop.third), - ShutterSpeedValue(3, false, Stop.half), - ShutterSpeedValue(3, false, Stop.third), - ShutterSpeedValue(4, false, Stop.full), - ShutterSpeedValue(5, false, Stop.third), - ShutterSpeedValue(6, false, Stop.half), - ShutterSpeedValue(6, false, Stop.third), - ShutterSpeedValue(8, false, Stop.full), - ShutterSpeedValue(10, false, Stop.third), - ShutterSpeedValue(12, false, Stop.half), - ShutterSpeedValue(13, false, Stop.third), - ShutterSpeedValue(16, false, Stop.full), + ShutterSpeedValue(2000, true, StopType.full), + ShutterSpeedValue(1600, true, StopType.third), + ShutterSpeedValue(1500, true, StopType.half), + ShutterSpeedValue(1250, true, StopType.third), + ShutterSpeedValue(1000, true, StopType.full), + ShutterSpeedValue(800, true, StopType.third), + ShutterSpeedValue(750, true, StopType.half), + ShutterSpeedValue(640, true, StopType.third), + ShutterSpeedValue(500, true, StopType.full), + ShutterSpeedValue(400, true, StopType.third), + ShutterSpeedValue(350, true, StopType.half), + ShutterSpeedValue(320, true, StopType.third), + ShutterSpeedValue(250, true, StopType.full), + ShutterSpeedValue(200, true, StopType.third), + ShutterSpeedValue(180, true, StopType.half), + ShutterSpeedValue(160, true, StopType.third), + ShutterSpeedValue(125, true, StopType.full), + ShutterSpeedValue(100, true, StopType.third), + ShutterSpeedValue(90, true, StopType.half), + ShutterSpeedValue(80, true, StopType.third), + ShutterSpeedValue(60, true, StopType.full), + ShutterSpeedValue(50, true, StopType.third), + ShutterSpeedValue(45, true, StopType.half), + ShutterSpeedValue(40, true, StopType.third), + ShutterSpeedValue(30, true, StopType.full), + ShutterSpeedValue(25, true, StopType.third), + ShutterSpeedValue(20, true, StopType.half), + ShutterSpeedValue(20, true, StopType.third), + ShutterSpeedValue(15, true, StopType.full), + ShutterSpeedValue(13, true, StopType.third), + ShutterSpeedValue(10, true, StopType.half), + ShutterSpeedValue(10, true, StopType.third), + ShutterSpeedValue(8, true, StopType.full), + ShutterSpeedValue(6, true, StopType.third), + ShutterSpeedValue(6, true, StopType.half), + ShutterSpeedValue(5, true, StopType.third), + ShutterSpeedValue(4, true, StopType.full), + ShutterSpeedValue(3, true, StopType.third), + ShutterSpeedValue(3, true, StopType.half), + ShutterSpeedValue(2.5, true, StopType.third), + ShutterSpeedValue(2, true, StopType.full), + ShutterSpeedValue(1.6, true, StopType.third), + ShutterSpeedValue(1.5, true, StopType.half), + ShutterSpeedValue(1.3, true, StopType.third), + ShutterSpeedValue(1, false, StopType.full), + ShutterSpeedValue(1.3, false, StopType.third), + ShutterSpeedValue(1.5, false, StopType.half), + ShutterSpeedValue(1.6, false, StopType.third), + ShutterSpeedValue(2, false, StopType.full), + ShutterSpeedValue(2.5, false, StopType.third), + ShutterSpeedValue(3, false, StopType.half), + ShutterSpeedValue(3, false, StopType.third), + ShutterSpeedValue(4, false, StopType.full), + ShutterSpeedValue(5, false, StopType.third), + ShutterSpeedValue(6, false, StopType.half), + ShutterSpeedValue(6, false, StopType.third), + ShutterSpeedValue(8, false, StopType.full), + ShutterSpeedValue(10, false, StopType.third), + ShutterSpeedValue(12, false, StopType.half), + ShutterSpeedValue(13, false, StopType.third), + ShutterSpeedValue(16, false, StopType.full), ]; diff --git a/lib/screens/metering/components/exposure_pairs_list/components/exposure_pair_item.dart b/lib/screens/metering/components/exposure_pairs_list/components/exposure_pair_item.dart index d60211a..219de3f 100644 --- a/lib/screens/metering/components/exposure_pairs_list/components/exposure_pair_item.dart +++ b/lib/screens/metering/components/exposure_pairs_list/components/exposure_pair_item.dart @@ -32,22 +32,22 @@ class ExposurePaitListItem extends StatelessWidget { TextStyle labelTextStyle(BuildContext context) { switch (value.stopType) { - case Stop.full: + case StopType.full: return Theme.of(context).textTheme.bodyLarge!; - case Stop.half: + case StopType.half: return Theme.of(context).textTheme.bodyMedium!; - case Stop.third: + case StopType.third: return Theme.of(context).textTheme.bodySmall!; } } double tickLength() { switch (value.stopType) { - case Stop.full: + case StopType.full: return Dimens.grid24; - case Stop.half: + case StopType.half: return Dimens.grid16; - case Stop.third: + case StopType.third: return Dimens.grid8; } } diff --git a/lib/screens/metering/metering_bloc.dart b/lib/screens/metering/metering_bloc.dart index b224cca..9890cda 100644 --- a/lib/screens/metering/metering_bloc.dart +++ b/lib/screens/metering/metering_bloc.dart @@ -8,7 +8,7 @@ import 'metering_event.dart'; import 'metering_state.dart'; class MeteringBloc extends Bloc { - final Stop stopType; + final StopType stopType; late final _apertureValues = apertureValues.whereStopType(stopType); late final _shutterSpeedValues = shutterSpeedValues.whereStopType(stopType); late final _isoValues = isoValues.whereStopType(stopType); @@ -53,17 +53,17 @@ class MeteringBloc extends Bloc { List _buildExposureValues(double ev) { late final int evSteps; switch (stopType) { - case Stop.full: + case StopType.full: evSteps = ev.floor(); break; - case Stop.half: + case StopType.half: evSteps = (ev / 0.5).floor(); break; - case Stop.third: + case StopType.third: evSteps = (ev / 0.3).floor(); break; } - final evOffset = _shutterSpeedValues.indexOf(const ShutterSpeedValue(1, false, Stop.full)) - evSteps; + final evOffset = _shutterSpeedValues.indexOf(const ShutterSpeedValue(1, false, StopType.full)) - evSteps; late final int apertureOffset; late final int shutterSpeedOffset; diff --git a/lib/utils/stop_type_provider.dart b/lib/utils/stop_type_provider.dart new file mode 100644 index 0000000..b3b51c2 --- /dev/null +++ b/lib/utils/stop_type_provider.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/models/photography_value.dart'; +import 'package:provider/provider.dart'; + +class StopTypeProvider extends StatefulWidget { + final Widget? child; + + const StopTypeProvider({this.child, super.key}); + + @override + State createState() => StopTypeProviderState(); +} + +class StopTypeProviderState extends State { + StopType stopType = StopType.full; + + @override + Widget build(BuildContext context) { + return Provider.value( + value: stopType, + child: Provider.value( + value: this, + child: widget.child, + ), + ); + } + + void setStopType(StopType type) { + setState(() { + stopType = type; + }); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 6ad2456..39d9cf6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: sdk: flutter flutter_bloc: ^8.1.1 material_color_utilities: ^0.2.0 + provider: ^6.0.4 dev_dependencies: google_fonts: ^3.0.1