diff --git a/lib/screens/metering/bloc_metering.dart b/lib/screens/metering/bloc_metering.dart index 753a7e7..6c3ab15 100644 --- a/lib/screens/metering/bloc_metering.dart +++ b/lib/screens/metering/bloc_metering.dart @@ -6,10 +6,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/volume_action.dart'; import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; -import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' - as communication_events; -import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart' - as communication_states; +import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events; +import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart' as communication_states; import 'package:lightmeter/screens/metering/event_metering.dart'; import 'package:lightmeter/screens/metering/state_metering.dart'; import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart'; @@ -45,8 +43,8 @@ class MeteringBloc extends Bloc { on(_onMeasure, transformer: droppable()); on(_onMeasured); on(_onMeasureError); - on(_onSettingsOpened); - on(_onSettingsClosed); + on(_onSettingsOpened); + on(_onSettingsClosed); } @override @@ -191,11 +189,11 @@ class MeteringBloc extends Bloc { } } - void _onSettingsOpened(SettingsOpenedEvent _, Emitter __) { - _communicationBloc.add(const communication_events.SettingsOpenedEvent()); + void _onSettingsOpened(ScreenOnTopOpenedEvent _, Emitter __) { + _communicationBloc.add(const communication_events.ScreenOnTopOpenedEvent()); } - void _onSettingsClosed(SettingsClosedEvent _, Emitter __) { - _communicationBloc.add(const communication_events.SettingsClosedEvent()); + void _onSettingsClosed(ScreenOnTopClosedEvent _, Emitter __) { + _communicationBloc.add(const communication_events.ScreenOnTopClosedEvent()); } } diff --git a/lib/screens/metering/communication/bloc_communication_metering.dart b/lib/screens/metering/communication/bloc_communication_metering.dart index 11ebe37..f80866c 100644 --- a/lib/screens/metering/communication/bloc_communication_metering.dart +++ b/lib/screens/metering/communication/bloc_communication_metering.dart @@ -3,15 +3,14 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'; import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'; -class MeteringCommunicationBloc - extends Bloc { +class MeteringCommunicationBloc extends Bloc { MeteringCommunicationBloc() : super(const InitState()) { // `MeasureState` is not const, so that `Bloc` treats each state as new and updates state stream // ignore: prefer_const_constructors on((_, emit) => emit(MeasureState())); on((event, emit) => emit(MeteringInProgressState(event.ev100))); on((event, emit) => emit(MeteringEndedState(event.ev100))); - on((_, emit) => emit(const SettingsOpenedState())); - on((_, emit) => emit(const SettingsClosedState())); + on((_, emit) => emit(const SettingsOpenedState())); + on((_, emit) => emit(const SettingsClosedState())); } } diff --git a/lib/screens/metering/communication/event_communication_metering.dart b/lib/screens/metering/communication/event_communication_metering.dart index c7e0fd8..8872fa0 100644 --- a/lib/screens/metering/communication/event_communication_metering.dart +++ b/lib/screens/metering/communication/event_communication_metering.dart @@ -48,10 +48,10 @@ class MeteringEndedEvent extends MeasuredEvent { int get hashCode => Object.hash(ev100, runtimeType); } -class SettingsOpenedEvent extends ScreenEvent { - const SettingsOpenedEvent(); +class ScreenOnTopOpenedEvent extends ScreenEvent { + const ScreenOnTopOpenedEvent(); } -class SettingsClosedEvent extends ScreenEvent { - const SettingsClosedEvent(); +class ScreenOnTopClosedEvent extends ScreenEvent { + const ScreenOnTopClosedEvent(); } diff --git a/lib/screens/metering/event_metering.dart b/lib/screens/metering/event_metering.dart index 0a39844..107eac2 100644 --- a/lib/screens/metering/event_metering.dart +++ b/lib/screens/metering/event_metering.dart @@ -39,10 +39,10 @@ class MeasureErrorEvent extends MeteringEvent { const MeasureErrorEvent({required this.isMetering}); } -class SettingsOpenedEvent extends MeteringEvent { - const SettingsOpenedEvent(); +class ScreenOnTopOpenedEvent extends MeteringEvent { + const ScreenOnTopOpenedEvent(); } -class SettingsClosedEvent extends MeteringEvent { - const SettingsClosedEvent(); +class ScreenOnTopClosedEvent extends MeteringEvent { + const ScreenOnTopClosedEvent(); } diff --git a/lib/screens/metering/screen_metering.dart b/lib/screens/metering/screen_metering.dart index e558706..2d0c792 100644 --- a/lib/screens/metering/screen_metering.dart +++ b/lib/screens/metering/screen_metering.dart @@ -34,7 +34,7 @@ class MeteringScreen extends StatelessWidget { nd: state.nd, onIsoChanged: (value) => context.read().add(IsoChangedEvent(value)), onNdChanged: (value) => context.read().add(NdChangedEvent(value)), - onExposurePairTap: (value) => Navigator.pushNamed(context, 'timer', arguments: value), + onExposurePairTap: (value) => pushNamed(context, 'timer', arguments: value), ), ), ), @@ -47,12 +47,7 @@ class MeteringScreen extends StatelessWidget { ? UserPreferencesProvider.of(context).toggleEvSourceType : null, onMeasure: () => context.read().add(const MeasureEvent()), - onSettings: () { - context.read().add(const SettingsOpenedEvent()); - Navigator.pushNamed(context, 'settings').then((_) { - context.read().add(const SettingsClosedEvent()); - }); - }, + onSettings: () => pushNamed(context, 'settings'), ), ), ], @@ -60,6 +55,13 @@ class MeteringScreen extends StatelessWidget { ), ); } + + void pushNamed(BuildContext context, String routeName, {Object? arguments}) { + context.read().add(const ScreenOnTopOpenedEvent()); + Navigator.pushNamed(context, routeName, arguments: arguments).then((_) { + context.read().add(const ScreenOnTopClosedEvent()); + }); + } } class _InheritedListeners extends StatelessWidget { diff --git a/test/screens/metering/bloc_metering_test.dart b/test/screens/metering/bloc_metering_test.dart index f07d35c..2e94aef 100644 --- a/test/screens/metering/bloc_metering_test.dart +++ b/test/screens/metering/bloc_metering_test.dart @@ -3,10 +3,8 @@ import 'package:lightmeter/data/models/volume_action.dart'; import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/screens/metering/bloc_metering.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; -import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' - as communication_events; -import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart' - as communication_states; +import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events; +import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart' as communication_states; import 'package:lightmeter/screens/metering/event_metering.dart'; import 'package:lightmeter/screens/metering/state_metering.dart'; import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart'; @@ -18,9 +16,9 @@ class _MockMeteringInteractor extends Mock implements MeteringInteractor {} class _MockVolumeKeysNotifier extends Mock implements VolumeKeysNotifier {} -class _MockMeteringCommunicationBloc extends MockBloc< - communication_events.MeteringCommunicationEvent, - communication_states.MeteringCommunicationState> implements MeteringCommunicationBloc {} +class _MockMeteringCommunicationBloc + extends MockBloc + implements MeteringCommunicationBloc {} void main() { late _MockMeteringInteractor meteringInteractor; @@ -515,20 +513,18 @@ void main() { ); group( - '`SettingOpenedEvent`/`SettingsClosedEvent`', + '`ScreenOnTopOpenedEvent`/`ScreenOnTopClosedEvent`', () { blocTest( 'Settings opened & closed', build: () => bloc, act: (bloc) async { - bloc.add(const SettingsOpenedEvent()); - bloc.add(const SettingsClosedEvent()); + bloc.add(const ScreenOnTopOpenedEvent()); + bloc.add(const ScreenOnTopClosedEvent()); }, verify: (_) { - verify(() => communicationBloc.add(const communication_events.SettingsOpenedEvent())) - .called(1); - verify(() => communicationBloc.add(const communication_events.SettingsClosedEvent())) - .called(1); + verify(() => communicationBloc.add(const communication_events.ScreenOnTopOpenedEvent())).called(1); + verify(() => communicationBloc.add(const communication_events.ScreenOnTopClosedEvent())).called(1); }, expect: () => [], ); diff --git a/test/screens/metering/communication/bloc_communication_metering_test.dart b/test/screens/metering/communication/bloc_communication_metering_test.dart index a04aab7..2609258 100644 --- a/test/screens/metering/communication/bloc_communication_metering_test.dart +++ b/test/screens/metering/communication/bloc_communication_metering_test.dart @@ -100,20 +100,20 @@ void main() { ); group( - '`SettingsOpenedEvent`/`SettingsClosedEvent`', + '`ScreenOnTopOpenedEvent`/`ScreenOnTopClosedEvent`', () { blocTest( 'Multiple consequtive settings events', build: () => bloc, act: (bloc) async { - bloc.add(const SettingsOpenedEvent()); - bloc.add(const SettingsOpenedEvent()); - bloc.add(const SettingsOpenedEvent()); - bloc.add(const SettingsClosedEvent()); - bloc.add(const SettingsClosedEvent()); - bloc.add(const SettingsClosedEvent()); - bloc.add(const SettingsOpenedEvent()); - bloc.add(const SettingsClosedEvent()); + bloc.add(const ScreenOnTopOpenedEvent()); + bloc.add(const ScreenOnTopOpenedEvent()); + bloc.add(const ScreenOnTopOpenedEvent()); + bloc.add(const ScreenOnTopClosedEvent()); + bloc.add(const ScreenOnTopClosedEvent()); + bloc.add(const ScreenOnTopClosedEvent()); + bloc.add(const ScreenOnTopOpenedEvent()); + bloc.add(const ScreenOnTopClosedEvent()); }, expect: () => [ isA(),