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-06-04 11:04:04 +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-06-04 11:04:04 +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
|
|
|
|
2022-11-26 18:14:51 +00:00
|
|
|
@override
|
2023-06-04 11:04:04 +00:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return _InheritedListeners(
|
|
|
|
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,
|
|
|
|
onFilmChanged: (value) =>
|
|
|
|
context.read<MeteringBloc>().add(FilmChangedEvent(value)),
|
|
|
|
onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(value)),
|
|
|
|
onNdChanged: (value) => context.read<MeteringBloc>().add(NdChangedEvent(value)),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
BlocBuilder<MeteringBloc, MeteringState>(
|
|
|
|
builder: (context, state) => MeteringBottomControlsProvider(
|
|
|
|
ev: state is MeteringDataState ? state.ev : null,
|
|
|
|
isMetering:
|
|
|
|
state is LoadingState || state is MeteringDataState && state.continuousMetering,
|
|
|
|
hasError: state is MeteringDataState && state.hasError,
|
|
|
|
onSwitchEvSourceType: context.get<Environment>().hasLightSensor
|
|
|
|
? EvSourceTypeProvider.of(context).toggleType
|
|
|
|
: null,
|
|
|
|
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
|
|
|
onSettings: () => Navigator.pushNamed(context, 'settings'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-11-26 18:14:51 +00:00
|
|
|
}
|
|
|
|
|
2023-06-04 11:04:04 +00:00
|
|
|
class _InheritedListeners extends StatelessWidget {
|
|
|
|
final Widget child;
|
2023-01-26 15:03:48 +00:00
|
|
|
|
2023-06-04 11:04:04 +00:00
|
|
|
const _InheritedListeners({required this.child});
|
2022-12-11 14:04:08 +00:00
|
|
|
|
2022-10-24 20:25:38 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-06-04 11:04:04 +00:00
|
|
|
return InheritedWidgetListener<EquipmentProfile>(
|
|
|
|
onDidChangeDependencies: (value) {
|
|
|
|
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
|
|
|
},
|
|
|
|
child: InheritedWidgetListener<StopType>(
|
|
|
|
onDidChangeDependencies: (value) {
|
|
|
|
context.read<MeteringBloc>().add(StopTypeChangedEvent(value));
|
|
|
|
},
|
|
|
|
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
|
|
|
aspect: MeteringScreenLayoutFeature.filmPicker,
|
|
|
|
onDidChangeDependencies: (value) {
|
|
|
|
if (!value) context.read<MeteringBloc>().add(const FilmChangedEvent(Film.other()));
|
|
|
|
},
|
|
|
|
child: child,
|
|
|
|
),
|
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;
|
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-06-04 11:04:04 +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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|