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';
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'package:lightmeter/data/models/ev_source_type.dart';
|
2023-02-19 10:26:14 +00:00
|
|
|
import 'package:lightmeter/data/models/exposure_pair.dart';
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'package:lightmeter/environment.dart';
|
2023-03-23 20:12:14 +00:00
|
|
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'package:lightmeter/providers/ev_source_type_provider.dart';
|
2023-03-03 21:04:28 +00:00
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2023-01-31 21:24:26 +00:00
|
|
|
import 'components/bottom_controls/provider_bottom_controls.dart';
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'components/camera_container/provider_container_camera.dart';
|
|
|
|
import 'components/light_sensor_container/provider_container_light_sensor.dart';
|
2022-12-14 17:33:38 +00:00
|
|
|
import 'bloc_metering.dart';
|
|
|
|
import 'event_metering.dart';
|
|
|
|
import 'state_metering.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2022-11-26 18:14:51 +00:00
|
|
|
class MeteringScreen extends StatefulWidget {
|
2022-12-11 14:09:10 +00:00
|
|
|
const MeteringScreen({super.key});
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2022-11-26 18:14:51 +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>();
|
|
|
|
|
2022-12-11 14:04:08 +00:00
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
2023-03-23 20:23:26 +00:00
|
|
|
_bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
|
2023-01-26 15:03:48 +00:00
|
|
|
_bloc.add(StopTypeChangedEvent(context.watch<StopType>()));
|
2022-12-11 14:04:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 20:25:38 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.background,
|
2023-01-29 16:57:47 +00:00
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: BlocBuilder<MeteringBloc, MeteringState>(
|
2023-02-19 10:26:14 +00:00
|
|
|
buildWhen: (_, current) => current is MeteringDataState,
|
|
|
|
builder: (_, state) => state is MeteringDataState
|
|
|
|
? _MeteringContainerBuidler(
|
2023-01-29 16:57:47 +00:00
|
|
|
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:26:14 +00:00
|
|
|
: const SizedBox.shrink(),
|
2023-01-26 15:03:48 +00:00
|
|
|
),
|
2023-01-29 16:57:47 +00:00
|
|
|
),
|
2023-02-18 17:17:39 +00:00
|
|
|
BlocBuilder<MeteringBloc, MeteringState>(
|
|
|
|
builder: (context, state) => MeteringBottomControlsProvider(
|
2023-02-19 10:26:14 +00:00
|
|
|
ev: state is MeteringDataState ? state.ev : null,
|
|
|
|
isMetering: state is LoadingState || state is MeteringInProgressState,
|
2023-02-18 17:17:39 +00:00
|
|
|
onSwitchEvSourceType: context.read<Environment>().hasLightSensor
|
|
|
|
? EvSourceTypeProvider.of(context).toggleType
|
|
|
|
: null,
|
|
|
|
onMeasure: () => _bloc.add(const MeasureEvent()),
|
|
|
|
onSettings: () => Navigator.pushNamed(context, 'settings'),
|
|
|
|
),
|
2023-01-29 16:57:47 +00:00
|
|
|
),
|
|
|
|
],
|
2022-10-24 20:25:38 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-02-19 10:26:14 +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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|