mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
cdf7372913
* wip * `MeteringScreenLayout = InheritedModelBase<MeteringScreenLayoutFeature, bool>` * removed `Provider` from providers folder * wip * Update pubspec.yaml * `context.get<MeteringInteractor>()` * `context.get<Environment>()` * `context.get<SettingsInteractor>()` * typo * fixed `MeteringScreenLayout` * fixed redundant vibrations
141 lines
5.4 KiB
Dart
141 lines
5.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:lightmeter/data/models/ev_source_type.dart';
|
|
import 'package:lightmeter/data/models/exposure_pair.dart';
|
|
import 'package:lightmeter/data/models/film.dart';
|
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
|
import 'package:lightmeter/environment.dart';
|
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
|
import 'package:lightmeter/providers/ev_source_type_provider.dart';
|
|
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';
|
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
|
|
class MeteringScreen extends StatelessWidget {
|
|
const MeteringScreen({super.key});
|
|
|
|
@override
|
|
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'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _InheritedListeners extends StatelessWidget {
|
|
final Widget child;
|
|
|
|
const _InheritedListeners({required this.child});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _MeteringContainerBuidler extends StatelessWidget {
|
|
final ExposurePair? fastest;
|
|
final ExposurePair? slowest;
|
|
final Film film;
|
|
final IsoValue iso;
|
|
final NdValue nd;
|
|
final ValueChanged<Film> onFilmChanged;
|
|
final ValueChanged<IsoValue> onIsoChanged;
|
|
final ValueChanged<NdValue> onNdChanged;
|
|
final List<ExposurePair> exposurePairs;
|
|
|
|
const _MeteringContainerBuidler({
|
|
required this.fastest,
|
|
required this.slowest,
|
|
required this.film,
|
|
required this.iso,
|
|
required this.nd,
|
|
required this.onFilmChanged,
|
|
required this.onIsoChanged,
|
|
required this.onNdChanged,
|
|
required this.exposurePairs,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return context.listen<EvSourceType>() == EvSourceType.camera
|
|
? CameraContainerProvider(
|
|
fastest: fastest,
|
|
slowest: slowest,
|
|
film: film,
|
|
iso: iso,
|
|
nd: nd,
|
|
onFilmChanged: onFilmChanged,
|
|
onIsoChanged: onIsoChanged,
|
|
onNdChanged: onNdChanged,
|
|
exposurePairs: exposurePairs,
|
|
)
|
|
: LightSensorContainerProvider(
|
|
fastest: fastest,
|
|
slowest: slowest,
|
|
film: film,
|
|
iso: iso,
|
|
nd: nd,
|
|
onFilmChanged: onFilmChanged,
|
|
onIsoChanged: onIsoChanged,
|
|
onNdChanged: onNdChanged,
|
|
exposurePairs: exposurePairs,
|
|
);
|
|
}
|
|
}
|