added StopTypeProvider

This commit is contained in:
Vadim 2022-10-30 21:06:51 +03:00
parent 0a36e112e1
commit f1a49a2295
9 changed files with 208 additions and 171 deletions

View file

@ -5,6 +5,7 @@ import 'models/photography_value.dart';
import 'res/theme.dart'; import 'res/theme.dart';
import 'screens/metering/metering_bloc.dart'; import 'screens/metering/metering_bloc.dart';
import 'screens/metering/metering_screen.dart'; import 'screens/metering/metering_screen.dart';
import 'utils/stop_type_provider.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -15,8 +16,9 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return StopTypeProvider(
create: (context) => MeteringBloc(Stop.third), child: BlocProvider(
create: (context) => MeteringBloc(context.read<StopType>()),
child: MaterialApp( child: MaterialApp(
title: 'Flutter Demo', title: 'Flutter Demo',
theme: ThemeData( theme: ThemeData(
@ -25,6 +27,7 @@ class MyApp extends StatelessWidget {
), ),
home: const MeteringScreen(), home: const MeteringScreen(),
), ),
),
); );
} }
} }

View file

@ -19,49 +19,49 @@ class ApertureValue extends PhotographyValue<double> {
} }
const List<ApertureValue> apertureValues = [ const List<ApertureValue> apertureValues = [
ApertureValue(1.0, Stop.full), ApertureValue(1.0, StopType.full),
ApertureValue(1.1, Stop.third), ApertureValue(1.1, StopType.third),
ApertureValue(1.2, Stop.half), ApertureValue(1.2, StopType.half),
ApertureValue(1.2, Stop.third), ApertureValue(1.2, StopType.third),
ApertureValue(1.4, Stop.full), ApertureValue(1.4, StopType.full),
ApertureValue(1.6, Stop.third), ApertureValue(1.6, StopType.third),
ApertureValue(1.7, Stop.half), ApertureValue(1.7, StopType.half),
ApertureValue(1.8, Stop.third), ApertureValue(1.8, StopType.third),
ApertureValue(2.0, Stop.full), ApertureValue(2.0, StopType.full),
ApertureValue(2.2, Stop.third), ApertureValue(2.2, StopType.third),
ApertureValue(2.4, Stop.half), ApertureValue(2.4, StopType.half),
ApertureValue(2.4, Stop.third), ApertureValue(2.4, StopType.third),
ApertureValue(2.8, Stop.full), ApertureValue(2.8, StopType.full),
ApertureValue(3.2, Stop.third), ApertureValue(3.2, StopType.third),
ApertureValue(3.3, Stop.half), ApertureValue(3.3, StopType.half),
ApertureValue(3.5, Stop.third), ApertureValue(3.5, StopType.third),
ApertureValue(4.0, Stop.full), ApertureValue(4.0, StopType.full),
ApertureValue(4.5, Stop.third), ApertureValue(4.5, StopType.third),
ApertureValue(4.8, Stop.half), ApertureValue(4.8, StopType.half),
ApertureValue(5.0, Stop.third), ApertureValue(5.0, StopType.third),
ApertureValue(5.6, Stop.full), ApertureValue(5.6, StopType.full),
ApertureValue(6.3, Stop.third), ApertureValue(6.3, StopType.third),
ApertureValue(6.7, Stop.half), ApertureValue(6.7, StopType.half),
ApertureValue(7.1, Stop.third), ApertureValue(7.1, StopType.third),
ApertureValue(8, Stop.full), ApertureValue(8, StopType.full),
ApertureValue(9, Stop.third), ApertureValue(9, StopType.third),
ApertureValue(9.5, Stop.half), ApertureValue(9.5, StopType.half),
ApertureValue(10, Stop.third), ApertureValue(10, StopType.third),
ApertureValue(11, Stop.full), ApertureValue(11, StopType.full),
ApertureValue(13, Stop.third), ApertureValue(13, StopType.third),
ApertureValue(13, Stop.half), ApertureValue(13, StopType.half),
ApertureValue(14, Stop.third), ApertureValue(14, StopType.third),
ApertureValue(16, Stop.full), ApertureValue(16, StopType.full),
ApertureValue(18, Stop.third), ApertureValue(18, StopType.third),
ApertureValue(19, Stop.half), ApertureValue(19, StopType.half),
ApertureValue(20, Stop.third), ApertureValue(20, StopType.third),
ApertureValue(22, Stop.full), ApertureValue(22, StopType.full),
ApertureValue(25, Stop.third), ApertureValue(25, StopType.third),
ApertureValue(27, Stop.half), ApertureValue(27, StopType.half),
ApertureValue(29, Stop.third), ApertureValue(29, StopType.third),
ApertureValue(32, Stop.full), ApertureValue(32, StopType.full),
ApertureValue(36, Stop.third), ApertureValue(36, StopType.third),
ApertureValue(38, Stop.half), ApertureValue(38, StopType.half),
ApertureValue(42, Stop.third), ApertureValue(42, StopType.third),
ApertureValue(45, Stop.full), ApertureValue(45, StopType.full),
]; ];

View file

@ -11,38 +11,38 @@ class IsoValue extends PhotographyValue<int> {
} }
const List<IsoValue> isoValues = [ const List<IsoValue> isoValues = [
IsoValue(3, Stop.full), IsoValue(3, StopType.full),
IsoValue(4, Stop.third), IsoValue(4, StopType.third),
IsoValue(5, Stop.third), IsoValue(5, StopType.third),
IsoValue(6, Stop.full), IsoValue(6, StopType.full),
IsoValue(8, Stop.third), IsoValue(8, StopType.third),
IsoValue(10, Stop.third), IsoValue(10, StopType.third),
IsoValue(12, Stop.full), IsoValue(12, StopType.full),
IsoValue(16, Stop.third), IsoValue(16, StopType.third),
IsoValue(20, Stop.third), IsoValue(20, StopType.third),
IsoValue(25, Stop.full), IsoValue(25, StopType.full),
IsoValue(32, Stop.third), IsoValue(32, StopType.third),
IsoValue(40, Stop.third), IsoValue(40, StopType.third),
IsoValue(50, Stop.full), IsoValue(50, StopType.full),
IsoValue(64, Stop.third), IsoValue(64, StopType.third),
IsoValue(80, Stop.third), IsoValue(80, StopType.third),
IsoValue(100, Stop.full), IsoValue(100, StopType.full),
IsoValue(125, Stop.third), IsoValue(125, StopType.third),
IsoValue(160, Stop.third), IsoValue(160, StopType.third),
IsoValue(200, Stop.full), IsoValue(200, StopType.full),
IsoValue(250, Stop.third), IsoValue(250, StopType.third),
IsoValue(320, Stop.third), IsoValue(320, StopType.third),
IsoValue(400, Stop.full), IsoValue(400, StopType.full),
IsoValue(500, Stop.third), IsoValue(500, StopType.third),
IsoValue(640, Stop.third), IsoValue(640, StopType.third),
IsoValue(800, Stop.full), IsoValue(800, StopType.full),
IsoValue(1000, Stop.third), IsoValue(1000, StopType.third),
IsoValue(1250, Stop.third), IsoValue(1250, StopType.third),
IsoValue(1600, Stop.full), IsoValue(1600, StopType.full),
IsoValue(2000, Stop.third), IsoValue(2000, StopType.third),
IsoValue(2500, Stop.third), IsoValue(2500, StopType.third),
IsoValue(3200, Stop.full), IsoValue(3200, StopType.full),
IsoValue(4000, Stop.third), IsoValue(4000, StopType.third),
IsoValue(5000, Stop.third), IsoValue(5000, StopType.third),
IsoValue(6400, Stop.full), IsoValue(6400, StopType.full),
]; ];

View file

@ -2,11 +2,11 @@ part 'aperture_value.dart';
part 'iso_value.dart'; part 'iso_value.dart';
part 'shutter_speed_value.dart'; part 'shutter_speed_value.dart';
enum Stop { full, half, third } enum StopType { full, half, third }
abstract class PhotographyValue<T> { abstract class PhotographyValue<T> {
final T rawValue; final T rawValue;
final Stop stopType; final StopType stopType;
const PhotographyValue(this.rawValue, this.stopType); const PhotographyValue(this.rawValue, this.stopType);
@ -14,20 +14,20 @@ abstract class PhotographyValue<T> {
} }
extension PhotographyValues<T extends PhotographyValue> on List<T> { extension PhotographyValues<T extends PhotographyValue> on List<T> {
List<T> whereStopType(Stop stopType) { List<T> whereStopType(StopType stopType) {
switch (stopType) { switch (stopType) {
case Stop.full: case StopType.full:
return where((e) => e.stopType == Stop.full).toList(); return where((e) => e.stopType == StopType.full).toList();
case Stop.half: case StopType.half:
return where((e) => e.stopType == Stop.full || e.stopType == Stop.half).toList(); return where((e) => e.stopType == StopType.full || e.stopType == StopType.half).toList();
case Stop.third: case StopType.third:
return where((e) => e.stopType == Stop.full || e.stopType == Stop.third).toList(); return where((e) => e.stopType == StopType.full || e.stopType == StopType.third).toList();
} }
} }
List<T> fullStops() => whereStopType(Stop.full); List<T> fullStops() => whereStopType(StopType.full);
List<T> halfStops() => whereStopType(Stop.half); List<T> halfStops() => whereStopType(StopType.half);
List<T> thirdStops() => whereStopType(Stop.third); List<T> thirdStops() => whereStopType(StopType.third);
} }

View file

@ -23,65 +23,65 @@ class ShutterSpeedValue extends PhotographyValue<double> {
} }
const List<ShutterSpeedValue> shutterSpeedValues = [ const List<ShutterSpeedValue> shutterSpeedValues = [
ShutterSpeedValue(2000, true, Stop.full), ShutterSpeedValue(2000, true, StopType.full),
ShutterSpeedValue(1600, true, Stop.third), ShutterSpeedValue(1600, true, StopType.third),
ShutterSpeedValue(1500, true, Stop.half), ShutterSpeedValue(1500, true, StopType.half),
ShutterSpeedValue(1250, true, Stop.third), ShutterSpeedValue(1250, true, StopType.third),
ShutterSpeedValue(1000, true, Stop.full), ShutterSpeedValue(1000, true, StopType.full),
ShutterSpeedValue(800, true, Stop.third), ShutterSpeedValue(800, true, StopType.third),
ShutterSpeedValue(750, true, Stop.half), ShutterSpeedValue(750, true, StopType.half),
ShutterSpeedValue(640, true, Stop.third), ShutterSpeedValue(640, true, StopType.third),
ShutterSpeedValue(500, true, Stop.full), ShutterSpeedValue(500, true, StopType.full),
ShutterSpeedValue(400, true, Stop.third), ShutterSpeedValue(400, true, StopType.third),
ShutterSpeedValue(350, true, Stop.half), ShutterSpeedValue(350, true, StopType.half),
ShutterSpeedValue(320, true, Stop.third), ShutterSpeedValue(320, true, StopType.third),
ShutterSpeedValue(250, true, Stop.full), ShutterSpeedValue(250, true, StopType.full),
ShutterSpeedValue(200, true, Stop.third), ShutterSpeedValue(200, true, StopType.third),
ShutterSpeedValue(180, true, Stop.half), ShutterSpeedValue(180, true, StopType.half),
ShutterSpeedValue(160, true, Stop.third), ShutterSpeedValue(160, true, StopType.third),
ShutterSpeedValue(125, true, Stop.full), ShutterSpeedValue(125, true, StopType.full),
ShutterSpeedValue(100, true, Stop.third), ShutterSpeedValue(100, true, StopType.third),
ShutterSpeedValue(90, true, Stop.half), ShutterSpeedValue(90, true, StopType.half),
ShutterSpeedValue(80, true, Stop.third), ShutterSpeedValue(80, true, StopType.third),
ShutterSpeedValue(60, true, Stop.full), ShutterSpeedValue(60, true, StopType.full),
ShutterSpeedValue(50, true, Stop.third), ShutterSpeedValue(50, true, StopType.third),
ShutterSpeedValue(45, true, Stop.half), ShutterSpeedValue(45, true, StopType.half),
ShutterSpeedValue(40, true, Stop.third), ShutterSpeedValue(40, true, StopType.third),
ShutterSpeedValue(30, true, Stop.full), ShutterSpeedValue(30, true, StopType.full),
ShutterSpeedValue(25, true, Stop.third), ShutterSpeedValue(25, true, StopType.third),
ShutterSpeedValue(20, true, Stop.half), ShutterSpeedValue(20, true, StopType.half),
ShutterSpeedValue(20, true, Stop.third), ShutterSpeedValue(20, true, StopType.third),
ShutterSpeedValue(15, true, Stop.full), ShutterSpeedValue(15, true, StopType.full),
ShutterSpeedValue(13, true, Stop.third), ShutterSpeedValue(13, true, StopType.third),
ShutterSpeedValue(10, true, Stop.half), ShutterSpeedValue(10, true, StopType.half),
ShutterSpeedValue(10, true, Stop.third), ShutterSpeedValue(10, true, StopType.third),
ShutterSpeedValue(8, true, Stop.full), ShutterSpeedValue(8, true, StopType.full),
ShutterSpeedValue(6, true, Stop.third), ShutterSpeedValue(6, true, StopType.third),
ShutterSpeedValue(6, true, Stop.half), ShutterSpeedValue(6, true, StopType.half),
ShutterSpeedValue(5, true, Stop.third), ShutterSpeedValue(5, true, StopType.third),
ShutterSpeedValue(4, true, Stop.full), ShutterSpeedValue(4, true, StopType.full),
ShutterSpeedValue(3, true, Stop.third), ShutterSpeedValue(3, true, StopType.third),
ShutterSpeedValue(3, true, Stop.half), ShutterSpeedValue(3, true, StopType.half),
ShutterSpeedValue(2.5, true, Stop.third), ShutterSpeedValue(2.5, true, StopType.third),
ShutterSpeedValue(2, true, Stop.full), ShutterSpeedValue(2, true, StopType.full),
ShutterSpeedValue(1.6, true, Stop.third), ShutterSpeedValue(1.6, true, StopType.third),
ShutterSpeedValue(1.5, true, Stop.half), ShutterSpeedValue(1.5, true, StopType.half),
ShutterSpeedValue(1.3, true, Stop.third), ShutterSpeedValue(1.3, true, StopType.third),
ShutterSpeedValue(1, false, Stop.full), ShutterSpeedValue(1, false, StopType.full),
ShutterSpeedValue(1.3, false, Stop.third), ShutterSpeedValue(1.3, false, StopType.third),
ShutterSpeedValue(1.5, false, Stop.half), ShutterSpeedValue(1.5, false, StopType.half),
ShutterSpeedValue(1.6, false, Stop.third), ShutterSpeedValue(1.6, false, StopType.third),
ShutterSpeedValue(2, false, Stop.full), ShutterSpeedValue(2, false, StopType.full),
ShutterSpeedValue(2.5, false, Stop.third), ShutterSpeedValue(2.5, false, StopType.third),
ShutterSpeedValue(3, false, Stop.half), ShutterSpeedValue(3, false, StopType.half),
ShutterSpeedValue(3, false, Stop.third), ShutterSpeedValue(3, false, StopType.third),
ShutterSpeedValue(4, false, Stop.full), ShutterSpeedValue(4, false, StopType.full),
ShutterSpeedValue(5, false, Stop.third), ShutterSpeedValue(5, false, StopType.third),
ShutterSpeedValue(6, false, Stop.half), ShutterSpeedValue(6, false, StopType.half),
ShutterSpeedValue(6, false, Stop.third), ShutterSpeedValue(6, false, StopType.third),
ShutterSpeedValue(8, false, Stop.full), ShutterSpeedValue(8, false, StopType.full),
ShutterSpeedValue(10, false, Stop.third), ShutterSpeedValue(10, false, StopType.third),
ShutterSpeedValue(12, false, Stop.half), ShutterSpeedValue(12, false, StopType.half),
ShutterSpeedValue(13, false, Stop.third), ShutterSpeedValue(13, false, StopType.third),
ShutterSpeedValue(16, false, Stop.full), ShutterSpeedValue(16, false, StopType.full),
]; ];

View file

@ -32,22 +32,22 @@ class ExposurePaitListItem<T extends PhotographyValue> extends StatelessWidget {
TextStyle labelTextStyle(BuildContext context) { TextStyle labelTextStyle(BuildContext context) {
switch (value.stopType) { switch (value.stopType) {
case Stop.full: case StopType.full:
return Theme.of(context).textTheme.bodyLarge!; return Theme.of(context).textTheme.bodyLarge!;
case Stop.half: case StopType.half:
return Theme.of(context).textTheme.bodyMedium!; return Theme.of(context).textTheme.bodyMedium!;
case Stop.third: case StopType.third:
return Theme.of(context).textTheme.bodySmall!; return Theme.of(context).textTheme.bodySmall!;
} }
} }
double tickLength() { double tickLength() {
switch (value.stopType) { switch (value.stopType) {
case Stop.full: case StopType.full:
return Dimens.grid24; return Dimens.grid24;
case Stop.half: case StopType.half:
return Dimens.grid16; return Dimens.grid16;
case Stop.third: case StopType.third:
return Dimens.grid8; return Dimens.grid8;
} }
} }

View file

@ -8,7 +8,7 @@ import 'metering_event.dart';
import 'metering_state.dart'; import 'metering_state.dart';
class MeteringBloc extends Bloc<MeteringEvent, MeteringState> { class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
final Stop stopType; final StopType stopType;
late final _apertureValues = apertureValues.whereStopType(stopType); late final _apertureValues = apertureValues.whereStopType(stopType);
late final _shutterSpeedValues = shutterSpeedValues.whereStopType(stopType); late final _shutterSpeedValues = shutterSpeedValues.whereStopType(stopType);
late final _isoValues = isoValues.whereStopType(stopType); late final _isoValues = isoValues.whereStopType(stopType);
@ -53,17 +53,17 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
List<ExposurePair> _buildExposureValues(double ev) { List<ExposurePair> _buildExposureValues(double ev) {
late final int evSteps; late final int evSteps;
switch (stopType) { switch (stopType) {
case Stop.full: case StopType.full:
evSteps = ev.floor(); evSteps = ev.floor();
break; break;
case Stop.half: case StopType.half:
evSteps = (ev / 0.5).floor(); evSteps = (ev / 0.5).floor();
break; break;
case Stop.third: case StopType.third:
evSteps = (ev / 0.3).floor(); evSteps = (ev / 0.3).floor();
break; 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 apertureOffset;
late final int shutterSpeedOffset; late final int shutterSpeedOffset;

View file

@ -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<StopTypeProvider> createState() => StopTypeProviderState();
}
class StopTypeProviderState extends State<StopTypeProvider> {
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;
});
}
}

View file

@ -11,6 +11,7 @@ dependencies:
sdk: flutter sdk: flutter
flutter_bloc: ^8.1.1 flutter_bloc: ^8.1.1
material_color_utilities: ^0.2.0 material_color_utilities: ^0.2.0
provider: ^6.0.4
dev_dependencies: dev_dependencies:
google_fonts: ^3.0.1 google_fonts: ^3.0.1