Compare commits

..

No commits in common. "c50baa4802a9e178142046c228e099bfcd6968d5" and "1f88c7d9a4ef710af161657bc0aac0136aeaa8a6" have entirely different histories.

15 changed files with 104 additions and 113 deletions

View file

@ -12,7 +12,9 @@ import 'package:lightmeter/utils/inherited_generics.dart';
class Application extends StatelessWidget {
final Environment env;
const Application(this.env, {super.key});
Application(this.env, {super.key});
final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();
@override
Widget build(BuildContext context) {
@ -30,15 +32,19 @@ class Application extends StatelessWidget {
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
builder: (context, child) => MediaQuery(
builder: (context, child) => InheritedWidgetBase<RouteObserver<ModalRoute>>(
data: routeObserver,
child: MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!,
),
),
initialRoute: "metering",
routes: {
"metering": (context) => const MeteringFlow(),
"settings": (context) => const SettingsFlow(),
},
navigatorObservers: [routeObserver],
),
)
: const SizedBox(),

View file

@ -4,5 +4,5 @@ import 'package:lightmeter/environment.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const Application(Environment.dev()));
runApp(Application(const Environment.dev()));
}

View file

@ -6,5 +6,5 @@ import 'package:lightmeter/firebase.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializeFirebase();
runApp(const Application(Environment.prod()));
runApp(Application(const Environment.prod()));
}

View file

@ -48,8 +48,6 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
on<MeasureEvent>(_onMeasure, transformer: droppable());
on<MeasuredEvent>(_onMeasured);
on<MeasureErrorEvent>(_onMeasureError);
on<SettingsOpenedEvent>(_onSettingsOpened);
on<SettingsClosedEvent>(_onSettingsClosed);
}
@override
@ -235,12 +233,4 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
add(const MeasureEvent());
}
}
void _onSettingsOpened(SettingsOpenedEvent _, Emitter __) {
_communicationBloc.add(const communication_events.SettingsOpenedEvent());
}
void _onSettingsClosed(SettingsClosedEvent _, Emitter __) {
_communicationBloc.add(const communication_events.SettingsClosedEvent());
}
}

View file

@ -11,7 +11,5 @@ class MeteringCommunicationBloc
on<MeasureEvent>((_, emit) => emit(MeasureState()));
on<MeteringInProgressEvent>((event, emit) => emit(MeteringInProgressState(event.ev100)));
on<MeteringEndedEvent>((event, emit) => emit(MeteringEndedState(event.ev100)));
on<SettingsOpenedEvent>((_, emit) => emit(const SettingsOpenedState()));
on<SettingsClosedEvent>((_, emit) => emit(const SettingsClosedState()));
}
}

View file

@ -47,11 +47,3 @@ class MeteringEndedEvent extends MeasuredEvent {
@override
int get hashCode => Object.hash(ev100, runtimeType);
}
class SettingsOpenedEvent extends ScreenEvent {
const SettingsOpenedEvent();
}
class SettingsClosedEvent extends ScreenEvent {
const SettingsClosedEvent();
}

View file

@ -51,11 +51,3 @@ class MeteringEndedState extends MeasuredState {
@override
int get hashCode => Object.hash(ev100, runtimeType);
}
class SettingsOpenedState extends SourceState {
const SettingsOpenedState();
}
class SettingsClosedState extends SourceState {
const SettingsClosedState();
}

View file

@ -40,8 +40,6 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
double? _ev100 = 0.0;
bool _settingsOpened = false;
CameraContainerBloc(
this._meteringInteractor,
this._volumeKeysNotifier,
@ -74,8 +72,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
@override
void onCommunicationState(communication_states.SourceState communicationState) {
switch (communicationState) {
case communication_states.MeasureState():
if (communicationState is communication_states.MeasureState) {
if (_canTakePhoto) {
_takePhoto().then((ev100Raw) {
if (ev100Raw != null) {
@ -87,13 +84,6 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
}
});
}
case communication_states.SettingsOpenedState():
_settingsOpened = true;
add(const DeinitializeEvent());
case communication_states.SettingsClosedState():
_settingsOpened = false;
add(const InitializeEvent());
default:
}
}
@ -166,7 +156,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
Future<void> _onDeinitialize(DeinitializeEvent _, Emitter emit) async {
emit(const CameraLoadingState());
await _cameraController?.dispose().then((_) => _cameraController = null);
unawaited(_cameraController?.dispose().then((_) => _cameraController = null));
}
Future<void> _onZoomChanged(ZoomChangedEvent event, Emitter emit) async {
@ -234,7 +224,6 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
}
Future<void> _appLifecycleStateObserver(AppLifecycleState state) async {
if (!_settingsOpened) {
switch (state) {
case AppLifecycleState.resumed:
add(const InitializeEvent());
@ -244,7 +233,6 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
default:
}
}
}
@visibleForTesting
void onVolumeKey() {

View file

@ -18,9 +18,10 @@ import 'package:lightmeter/screens/metering/components/camera_container/state_co
import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
import 'package:lightmeter/screens/metering/components/shared/metering_top_bar/widget_top_bar_metering.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/widget_container_readings.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class CameraContainer extends StatelessWidget {
class CameraContainer extends StatefulWidget {
final ExposurePair? fastest;
final ExposurePair? slowest;
final Film film;
@ -44,6 +45,29 @@ class CameraContainer extends StatelessWidget {
super.key,
});
@override
State<CameraContainer> createState() => _CameraContainerState();
}
class _CameraContainerState extends State<CameraContainer> with RouteAware {
@override
void didChangeDependencies() {
super.didChangeDependencies();
context.get<RouteObserver<ModalRoute>>().subscribe(this, ModalRoute.of(context)!);
}
@override
void didPushNext() {
super.didPushNext();
context.read<CameraContainerBloc>().add(const DeinitializeEvent());
}
@override
void didPopNext() {
super.didPopNext();
context.read<CameraContainerBloc>().add(const InitializeEvent());
}
@override
Widget build(BuildContext context) {
final double cameraViewHeight =
@ -75,14 +99,14 @@ class CameraContainer extends StatelessWidget {
children: [
MeteringTopBar(
readingsContainer: ReadingsContainer(
fastest: fastest,
slowest: slowest,
film: film,
iso: iso,
nd: nd,
onFilmChanged: onFilmChanged,
onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged,
fastest: widget.fastest,
slowest: widget.slowest,
film: widget.film,
iso: widget.iso,
nd: widget.nd,
onFilmChanged: widget.onFilmChanged,
onIsoChanged: widget.onIsoChanged,
onNdChanged: widget.onNdChanged,
),
appendixHeight: topBarOverflow,
preview: const _CameraViewBuilder(),
@ -92,7 +116,7 @@ class CameraContainer extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
child: _MiddleContentWrapper(
topBarOverflow: topBarOverflow,
leftContent: ExposurePairsList(exposurePairs),
leftContent: ExposurePairsList(widget.exposurePairs),
rightContent: const _CameraControlsBuilder(),
),
),

View file

@ -31,16 +31,12 @@ class LightSensorContainerBloc
@override
void onCommunicationState(communication_states.SourceState communicationState) {
switch (communicationState) {
case communication_states.MeasureState():
if (communicationState is communication_states.MeasureState) {
if (_luxSubscriptions == null) {
_startMetering();
} else {
_cancelMetering();
}
case communication_states.SettingsOpenedState():
_cancelMetering();
default:
}
}

View file

@ -1,13 +1,17 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart';
import 'package:lightmeter/screens/metering/components/light_sensor_container/event_container_light_sensor.dart';
import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
import 'package:lightmeter/screens/metering/components/shared/metering_top_bar/widget_top_bar_metering.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/widget_container_readings.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class LightSensorContainer extends StatelessWidget {
class LightSensorContainer extends StatefulWidget {
final ExposurePair? fastest;
final ExposurePair? slowest;
final Film film;
@ -31,26 +35,43 @@ class LightSensorContainer extends StatelessWidget {
super.key,
});
@override
State<LightSensorContainer> createState() => _LightSensorContainerState();
}
class _LightSensorContainerState extends State<LightSensorContainer> with RouteAware {
@override
void didChangeDependencies() {
super.didChangeDependencies();
context.get<RouteObserver<ModalRoute>>().subscribe(this, ModalRoute.of(context)!);
}
@override
void didPushNext() {
super.didPushNext();
context.read<LightSensorContainerBloc>().add(const CancelLuxMeteringEvent());
}
@override
Widget build(BuildContext context) {
return Column(
children: [
MeteringTopBar(
readingsContainer: ReadingsContainer(
fastest: fastest,
slowest: slowest,
film: film,
iso: iso,
nd: nd,
onFilmChanged: onFilmChanged,
onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged,
fastest: widget.fastest,
slowest: widget.slowest,
film: widget.film,
iso: widget.iso,
nd: widget.nd,
onFilmChanged: widget.onFilmChanged,
onIsoChanged: widget.onIsoChanged,
onNdChanged: widget.onNdChanged,
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
child: Center(child: ExposurePairsList(exposurePairs)),
child: Center(child: ExposurePairsList(widget.exposurePairs)),
),
),
],

View file

@ -10,6 +10,7 @@ class VolumeKeysNotifier extends ChangeNotifier with RouteAware {
VolumeKey _value = VolumeKey.up;
VolumeKeysNotifier(this.volumeEventsService) {
// TODO: add RouteObserver and disable overriden action if SettingScreen is opened
_volumeKeysSubscription = volumeEventsService
.volumeButtonsEventStream()
.map((event) => event == 24 ? VolumeKey.up : VolumeKey.down)

View file

@ -45,11 +45,3 @@ class MeasureErrorEvent extends MeteringEvent {
const MeasureErrorEvent({required this.isMetering});
}
class SettingsOpenedEvent extends MeteringEvent {
const SettingsOpenedEvent();
}
class SettingsClosedEvent extends MeteringEvent {
const SettingsClosedEvent();
}

View file

@ -50,12 +50,7 @@ class MeteringScreen extends StatelessWidget {
? EvSourceTypeProvider.of(context).toggleType
: null,
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
onSettings: () {
context.read<MeteringBloc>().add(const SettingsOpenedEvent());
Navigator.pushNamed(context, 'settings').then((value) {
context.read<MeteringBloc>().add(const SettingsClosedEvent());
});
},
onSettings: () => Navigator.pushNamed(context, 'settings'),
),
),
],

View file

@ -11,10 +11,6 @@ class VolumeActionsListTileBloc extends Cubit<VolumeAction> {
void onVolumeActionChanged(VolumeAction value) {
_settingsInteractor.setVolumeAction(value);
// while in settings we allow system to handle volume
// so that volume keys action works only when necessary - on the metering screen
_settingsInteractor.disableVolumeHandling();
emit(value);
}
}