diff --git a/lib/photobooth/bloc/photobooth_bloc.dart b/lib/photobooth/bloc/photobooth_bloc.dart index 087414db..91a663db 100644 --- a/lib/photobooth/bloc/photobooth_bloc.dart +++ b/lib/photobooth/bloc/photobooth_bloc.dart @@ -12,7 +12,7 @@ part 'photobooth_state.dart'; typedef UuidGetter = String Function(); -const _debounceDuration = Duration(milliseconds: 100); +const _debounceDuration = Duration(milliseconds: 16); class PhotoboothBloc extends Bloc { PhotoboothBloc([UuidGetter? uuid]) diff --git a/lib/photobooth/view/photobooth_page.dart b/lib/photobooth/view/photobooth_page.dart index b0125fc3..cd200179 100644 --- a/lib/photobooth/view/photobooth_page.dart +++ b/lib/photobooth/view/photobooth_page.dart @@ -6,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:io_photobooth/photobooth/photobooth.dart'; import 'package:io_photobooth/stickers/stickers.dart'; import 'package:photobooth_ui/photobooth_ui.dart'; +import 'package:very_good_analysis/very_good_analysis.dart'; const _videoConstraints = VideoConstraints( facingMode: FacingMode( @@ -23,8 +24,6 @@ class PhotoboothPage extends StatelessWidget { return AppPageRoute(builder: (_) => const PhotoboothPage()); } - static const String name = 'PhotoboothPage'; - @override Widget build(BuildContext context) { return BlocProvider( @@ -32,7 +31,6 @@ class PhotoboothPage extends StatelessWidget { child: Navigator( onGenerateRoute: (_) => AppPageRoute( builder: (_) => const PhotoboothView(), - settings: const RouteSettings(name: name), ), ), ); @@ -91,8 +89,7 @@ class _PhotoboothViewState extends State { .add(PhotoCaptured(aspectRatio: aspectRatio, image: picture)); final stickersPage = StickersPage.route(); await _stop(); - await Navigator.of(context).push(stickersPage); - await _play(); + unawaited(Navigator.of(context).pushReplacement(stickersPage)); } @override diff --git a/lib/share/view/share_page.dart b/lib/share/view/share_page.dart index 687ab6d8..a2001acc 100644 --- a/lib/share/view/share_page.dart +++ b/lib/share/view/share_page.dart @@ -7,6 +7,7 @@ import 'package:io_photobooth/share/share.dart'; import 'package:photobooth_ui/photobooth_ui.dart'; import 'package:photos_repository/photos_repository.dart'; import 'package:provider/provider.dart'; +import 'package:very_good_analysis/very_good_analysis.dart'; class SharePage extends StatelessWidget { const SharePage({Key? key}) : super(key: key); @@ -79,8 +80,8 @@ class _ShareRetakeButton extends StatelessWidget { ); if (confirmed) { context.read().add(const PhotoClearAllTapped()); - Navigator.of(context).popUntil( - (route) => route.settings.name == PhotoboothPage.name, + unawaited( + Navigator.of(context).pushReplacement(PhotoboothPage.route()), ); } }, diff --git a/lib/stickers/view/stickers_page.dart b/lib/stickers/view/stickers_page.dart index ff701e5f..e88c54c1 100644 --- a/lib/stickers/view/stickers_page.dart +++ b/lib/stickers/view/stickers_page.dart @@ -187,7 +187,9 @@ class _RetakeButton extends StatelessWidget { ); if (confirmed) { context.read().add(const PhotoClearAllTapped()); - Navigator.of(context).pop(); + unawaited( + Navigator.of(context).pushReplacement(PhotoboothPage.route()), + ); } }, message: l10n.retakeButtonTooltip, @@ -214,7 +216,7 @@ class _NextButton extends StatelessWidget { portraitChild: const _NextConfirmationBottomSheet(), ); if (confirmed) { - unawaited(Navigator.of(context).push(SharePage.route())); + unawaited(Navigator.of(context).pushReplacement(SharePage.route())); } }, child: Image.asset( diff --git a/test/photobooth/view/photobooth_page_test.dart b/test/photobooth/view/photobooth_page_test.dart index 896cdb27..f3313ee8 100644 --- a/test/photobooth/view/photobooth_page_test.dart +++ b/test/photobooth/view/photobooth_page_test.dart @@ -320,18 +320,6 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(StickersPage), findsOneWidget); - - final retakeButtonFinder = find.byKey( - const Key('stickersPage_retake_appTooltipButton'), - ); - tester.widget(retakeButtonFinder).onPressed(); - await tester.pumpAndSettle(); - - tester.widget(find.byType(ElevatedButton)).onPressed!(); - - await tester.pumpAndSettle(); - - expect(find.byType(PhotoboothView), findsOneWidget); }); }); diff --git a/test/share/view/share_page_test.dart b/test/share/view/share_page_test.dart index a6b9a3f1..eec6b6e7 100644 --- a/test/share/view/share_page_test.dart +++ b/test/share/view/share_page_test.dart @@ -360,43 +360,12 @@ void main() { testWidgets( 'tapping on retake button + close ' 'does not go back to PhotoboothPage', (tester) async { - const photoboothPage = Key('photoboothPage'); await tester.pumpApp( - Builder( - builder: (context) { - return ElevatedButton( - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => const SizedBox(key: photoboothPage), - settings: RouteSettings(name: PhotoboothPage.name), - ), - ); - - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => const SizedBox(), - settings: RouteSettings(name: 'IntermediatePage'), - ), - ); - - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => Scaffold(body: ShareView()), - ), - ); - }, - child: const SizedBox(), - ); - }, - ), + ShareView(), photoboothBloc: photoboothBloc, shareBloc: shareBloc, ); - await tester.tap(find.byType(ElevatedButton)); - await tester.pumpAndSettle(); - final retakeButtonFinder = find.byKey( const Key('sharePage_retake_appTooltipButton'), ); @@ -409,7 +378,7 @@ void main() { await tester.pumpAndSettle(); expect(retakeButtonFinder, findsOneWidget); - expect(find.byKey(photoboothPage), findsNothing); + expect(find.byType(PhotoboothPage), findsNothing); verifyNever(() => photoboothBloc.add(PhotoClearAllTapped())); }); @@ -417,43 +386,12 @@ void main() { testWidgets( 'tapping on retake button + cancel ' 'does not go back to PhotoboothPage', (tester) async { - const photoboothPage = Key('photoboothPage'); await tester.pumpApp( - Builder( - builder: (context) { - return ElevatedButton( - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => const SizedBox(key: photoboothPage), - settings: RouteSettings(name: PhotoboothPage.name), - ), - ); - - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => const SizedBox(), - settings: RouteSettings(name: 'IntermediatePage'), - ), - ); - - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => Scaffold(body: ShareView()), - ), - ); - }, - child: const SizedBox(), - ); - }, - ), + ShareView(), photoboothBloc: photoboothBloc, shareBloc: shareBloc, ); - await tester.tap(find.byType(ElevatedButton)); - await tester.pumpAndSettle(); - final retakeButtonFinder = find.byKey( const Key('sharePage_retake_appTooltipButton'), ); @@ -470,7 +408,7 @@ void main() { await tester.pumpAndSettle(); expect(retakeButtonFinder, findsOneWidget); - expect(find.byKey(photoboothPage), findsNothing); + expect(find.byType(PhotoboothPage), findsNothing); verifyNever(() => photoboothBloc.add(PhotoClearAllTapped())); }); @@ -478,43 +416,12 @@ void main() { testWidgets( 'tapping on retake button + confirm goes back to PhotoboothPage', (tester) async { - const photoboothPage = Key('photoboothPage'); await tester.pumpApp( - Builder( - builder: (context) { - return ElevatedButton( - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => const SizedBox(key: photoboothPage), - settings: RouteSettings(name: PhotoboothPage.name), - ), - ); - - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => const SizedBox(), - settings: RouteSettings(name: 'IntermediatePage'), - ), - ); - - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => Scaffold(body: ShareView()), - ), - ); - }, - child: const SizedBox(), - ); - }, - ), + ShareView(), photoboothBloc: photoboothBloc, shareBloc: shareBloc, ); - await tester.tap(find.byType(ElevatedButton)); - await tester.pumpAndSettle(); - final retakeButtonFinder = find.byKey( const Key('sharePage_retake_appTooltipButton'), ); @@ -531,7 +438,7 @@ void main() { await tester.pumpAndSettle(); expect(retakeButtonFinder, findsNothing); - expect(find.byKey(photoboothPage), findsOneWidget); + expect(find.byType(PhotoboothPage), findsOneWidget); verify(() => photoboothBloc.add(PhotoClearAllTapped())).called(1); }); diff --git a/test/stickers/view/stickers_page_test.dart b/test/stickers/view/stickers_page_test.dart index 9c8e8617..ccdcb100 100644 --- a/test/stickers/view/stickers_page_test.dart +++ b/test/stickers/view/stickers_page_test.dart @@ -370,33 +370,16 @@ void main() { expect(find.byKey(initialPage), findsNothing); }); - testWidgets('tapping on retake + confirm pops route and clears props', - (tester) async { - const initialPage = Key('__target__'); - await tester.pumpApp(Builder( - builder: (context) { - return ElevatedButton( - key: initialPage, - onPressed: () => Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => MultiBlocProvider( - providers: [ - BlocProvider.value(value: photoboothBloc), - BlocProvider.value(value: stickersBloc), - ], - child: StickersView(), - ), - ), - ), - child: const SizedBox(), - ); - }, - )); - await tester.tap(find.byType(ElevatedButton)); - await tester.pumpAndSettle(); + testWidgets( + 'tapping on retake + confirm replaces route with PhotoboothPage' + ' and clears props', (tester) async { + await tester.pumpApp( + BlocProvider.value(value: stickersBloc, child: StickersView()), + photoboothBloc: photoboothBloc, + ); expect(find.byType(StickersView), findsOneWidget); - expect(find.byKey(initialPage), findsNothing); + expect(find.byType(PhotoboothPage), findsNothing); final retakeButtonFinder = find.byKey( const Key('stickersPage_retake_appTooltipButton'), @@ -413,7 +396,7 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(StickersView), findsNothing); - expect(find.byKey(initialPage), findsOneWidget); + expect(find.byType(PhotoboothPage), findsOneWidget); }); testWidgets('tapping next + cancel does not route to SharePage',