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-04-01 19:04:55 +00:00
|
|
|
import 'package:lightmeter/data/models/film.dart';
|
2023-04-05 19:15:11 +00:00
|
|
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'package:lightmeter/environment.dart';
|
2023-03-30 19:24:18 +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-05-11 13:30:18 +00:00
|
|
|
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/components/bottom_controls/provider_bottom_controls.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/components/camera_container/provider_container_camera.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/event_metering.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/state_metering.dart';
|
2023-05-17 08:23:32 +00:00
|
|
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
2023-03-30 19:24:18 +00:00
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2023-05-18 17:56:13 +00:00
|
|
|
class MeteringScreen extends StatelessWidget {
|
2022-12-11 14:09:10 +00:00
|
|
|
const MeteringScreen({super.key});
|
2022-10-24 20:25:38 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-17 08:50:33 +00:00
|
|
|
return _InheritedListeners(
|
2023-05-17 08:23:32 +00:00
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.background,
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: BlocBuilder<MeteringBloc, MeteringState>(
|
|
|
|
builder: (_, state) => _MeteringContainerBuidler(
|
|
|
|
fastest: state is MeteringDataState ? state.fastest : null,
|
|
|
|
slowest: state is MeteringDataState ? state.slowest : null,
|
|
|
|
exposurePairs: state is MeteringDataState ? state.exposurePairs : [],
|
|
|
|
film: state.film,
|
|
|
|
iso: state.iso,
|
|
|
|
nd: state.nd,
|
2023-05-18 17:56:13 +00:00
|
|
|
onFilmChanged: (value) =>
|
|
|
|
context.read<MeteringBloc>().add(FilmChangedEvent(value)),
|
|
|
|
onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(value)),
|
|
|
|
onNdChanged: (value) => context.read<MeteringBloc>().add(NdChangedEvent(value)),
|
2023-05-17 08:23:32 +00:00
|
|
|
),
|
2023-05-16 09:47:53 +00:00
|
|
|
),
|
2023-01-26 15:03:48 +00:00
|
|
|
),
|
2023-05-17 08:23:32 +00:00
|
|
|
BlocBuilder<MeteringBloc, MeteringState>(
|
|
|
|
builder: (context, state) => MeteringBottomControlsProvider(
|
|
|
|
ev: state is MeteringDataState ? state.ev : null,
|
2023-05-18 17:56:13 +00:00
|
|
|
isMetering:
|
|
|
|
state is LoadingState || state is MeteringDataState && state.continuousMetering,
|
2023-05-17 08:23:32 +00:00
|
|
|
hasError: state is MeteringDataState && state.hasError,
|
2023-05-18 18:20:15 +00:00
|
|
|
onSwitchEvSourceType: context.get<Environment>().hasLightSensor
|
2023-05-17 08:23:32 +00:00
|
|
|
? EvSourceTypeProvider.of(context).toggleType
|
|
|
|
: null,
|
2023-05-18 17:56:13 +00:00
|
|
|
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
2023-05-17 08:23:32 +00:00
|
|
|
onSettings: () => Navigator.pushNamed(context, 'settings'),
|
|
|
|
),
|
2023-02-18 17:17:39 +00:00
|
|
|
),
|
2023-05-17 08:23:32 +00:00
|
|
|
],
|
|
|
|
),
|
2022-10-24 20:25:38 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-02-19 10:26:14 +00:00
|
|
|
|
2023-05-17 08:50:33 +00:00
|
|
|
class _InheritedListeners extends StatelessWidget {
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
const _InheritedListeners({required this.child});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-18 17:56:13 +00:00
|
|
|
return InheritedWidgetListener<EquipmentProfile>(
|
2023-05-17 08:50:33 +00:00
|
|
|
onDidChangeDependencies: (value) {
|
2023-05-18 17:56:13 +00:00
|
|
|
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
2023-05-17 08:50:33 +00:00
|
|
|
},
|
2023-05-18 17:56:13 +00:00
|
|
|
child: InheritedWidgetListener<StopType>(
|
2023-05-17 08:50:33 +00:00
|
|
|
onDidChangeDependencies: (value) {
|
2023-05-18 17:56:13 +00:00
|
|
|
context.read<MeteringBloc>().add(StopTypeChangedEvent(value));
|
2023-05-17 08:50:33 +00:00
|
|
|
},
|
2023-05-18 17:56:13 +00:00
|
|
|
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
|
|
|
aspect: MeteringScreenLayoutFeature.filmPicker,
|
|
|
|
onDidChangeDependencies: (value) {
|
|
|
|
if (!value) context.read<MeteringBloc>().add(const FilmChangedEvent(Film.other()));
|
|
|
|
},
|
|
|
|
child: child,
|
|
|
|
),
|
2023-05-17 08:50:33 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-19 10:26:14 +00:00
|
|
|
class _MeteringContainerBuidler extends StatelessWidget {
|
|
|
|
final ExposurePair? fastest;
|
|
|
|
final ExposurePair? slowest;
|
2023-04-01 19:04:55 +00:00
|
|
|
final Film film;
|
2023-02-19 10:26:14 +00:00
|
|
|
final IsoValue iso;
|
|
|
|
final NdValue nd;
|
2023-04-01 19:04:55 +00:00
|
|
|
final ValueChanged<Film> onFilmChanged;
|
2023-02-19 10:26:14 +00:00
|
|
|
final ValueChanged<IsoValue> onIsoChanged;
|
|
|
|
final ValueChanged<NdValue> onNdChanged;
|
|
|
|
final List<ExposurePair> exposurePairs;
|
|
|
|
|
|
|
|
const _MeteringContainerBuidler({
|
|
|
|
required this.fastest,
|
|
|
|
required this.slowest,
|
2023-04-01 19:04:55 +00:00
|
|
|
required this.film,
|
2023-02-19 10:26:14 +00:00
|
|
|
required this.iso,
|
|
|
|
required this.nd,
|
2023-04-01 19:04:55 +00:00
|
|
|
required this.onFilmChanged,
|
2023-02-19 10:26:14 +00:00
|
|
|
required this.onIsoChanged,
|
|
|
|
required this.onNdChanged,
|
|
|
|
required this.exposurePairs,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-18 17:56:13 +00:00
|
|
|
return context.listen<EvSourceType>() == EvSourceType.camera
|
2023-02-19 10:26:14 +00:00
|
|
|
? CameraContainerProvider(
|
|
|
|
fastest: fastest,
|
|
|
|
slowest: slowest,
|
2023-04-01 19:04:55 +00:00
|
|
|
film: film,
|
2023-02-19 10:26:14 +00:00
|
|
|
iso: iso,
|
|
|
|
nd: nd,
|
2023-04-01 19:04:55 +00:00
|
|
|
onFilmChanged: onFilmChanged,
|
2023-02-19 10:26:14 +00:00
|
|
|
onIsoChanged: onIsoChanged,
|
|
|
|
onNdChanged: onNdChanged,
|
|
|
|
exposurePairs: exposurePairs,
|
|
|
|
)
|
|
|
|
: LightSensorContainerProvider(
|
|
|
|
fastest: fastest,
|
|
|
|
slowest: slowest,
|
2023-04-01 19:04:55 +00:00
|
|
|
film: film,
|
2023-02-19 10:26:14 +00:00
|
|
|
iso: iso,
|
|
|
|
nd: nd,
|
2023-04-01 19:04:55 +00:00
|
|
|
onFilmChanged: onFilmChanged,
|
2023-02-19 10:26:14 +00:00
|
|
|
onIsoChanged: onIsoChanged,
|
|
|
|
onNdChanged: onNdChanged,
|
|
|
|
exposurePairs: exposurePairs,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|