m3_lightmeter/lib/screens/metering/screen_metering.dart

115 lines
4 KiB
Dart
Raw Permalink Normal View History

2022-10-24 20:25:38 +00:00
import 'package:flutter/material.dart';
2022-10-29 18:02:45 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/ev_source_type.dart';
2023-02-19 10:24:42 +00:00
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/data/models/photography_values/iso_value.dart';
import 'package:lightmeter/data/models/photography_values/nd_value.dart';
import 'package:lightmeter/data/models/photography_values/photography_value.dart';
import 'package:lightmeter/environment.dart';
import 'package:lightmeter/providers/ev_source_type_provider.dart';
2022-10-24 20:25:38 +00:00
import 'components/bottom_controls/provider_bottom_controls.dart';
import 'components/camera_container/provider_container_camera.dart';
import 'components/light_sensor_container/provider_container_light_sensor.dart';
import 'bloc_metering.dart';
import 'event_metering.dart';
import 'state_metering.dart';
2022-10-24 20:25:38 +00:00
class MeteringScreen extends StatefulWidget {
const MeteringScreen({super.key});
2022-10-24 20:25:38 +00:00
@override
State<MeteringScreen> createState() => _MeteringScreenState();
}
2022-11-26 19:29:00 +00:00
class _MeteringScreenState extends State<MeteringScreen> {
2023-01-26 15:03:48 +00:00
MeteringBloc get _bloc => context.read<MeteringBloc>();
@override
void didChangeDependencies() {
super.didChangeDependencies();
2023-01-26 15:03:48 +00:00
_bloc.add(StopTypeChangedEvent(context.watch<StopType>()));
}
2022-10-24 20:25:38 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
body: Column(
children: [
Expanded(
child: BlocBuilder<MeteringBloc, MeteringState>(
2023-02-19 10:24:42 +00:00
buildWhen: (_, current) => current is MeteringDataState,
builder: (_, state) => state is MeteringDataState
? _MeteringContainerBuidler(
fastest: state.fastest,
slowest: state.slowest,
iso: state.iso,
nd: state.nd,
onIsoChanged: (value) => _bloc.add(IsoChangedEvent(value)),
onNdChanged: (value) => _bloc.add(NdChangedEvent(value)),
exposurePairs: state.exposurePairs,
)
2023-02-19 10:24:42 +00:00
: const SizedBox.shrink(),
2023-01-26 15:03:48 +00:00
),
),
BlocBuilder<MeteringBloc, MeteringState>(
builder: (context, state) => MeteringBottomControlsProvider(
2023-02-19 10:24:42 +00:00
ev: state is MeteringDataState ? state.ev : null,
isMetering: state is LoadingState || state is MeteringInProgressState,
onSwitchEvSourceType: context.read<Environment>().hasLightSensor
? EvSourceTypeProvider.of(context).toggleType
: null,
onMeasure: () => _bloc.add(const MeasureEvent()),
onSettings: () => Navigator.pushNamed(context, 'settings'),
),
),
],
2022-10-24 20:25:38 +00:00
),
);
}
}
2023-02-19 10:24:42 +00:00
class _MeteringContainerBuidler extends StatelessWidget {
final ExposurePair? fastest;
final ExposurePair? slowest;
final IsoValue iso;
final NdValue nd;
final ValueChanged<IsoValue> onIsoChanged;
final ValueChanged<NdValue> onNdChanged;
final List<ExposurePair> exposurePairs;
const _MeteringContainerBuidler({
required this.fastest,
required this.slowest,
required this.iso,
required this.nd,
required this.onIsoChanged,
required this.onNdChanged,
required this.exposurePairs,
});
@override
Widget build(BuildContext context) {
return context.watch<EvSourceType>() == EvSourceType.camera
? CameraContainerProvider(
fastest: fastest,
slowest: slowest,
iso: iso,
nd: nd,
onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged,
exposurePairs: exposurePairs,
)
: LightSensorContainerProvider(
fastest: fastest,
slowest: slowest,
iso: iso,
nd: nd,
onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged,
exposurePairs: exposurePairs,
);
}
}