Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
fix: asset distortion upon viewport resize (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed May 13, 2021
1 parent 23557df commit 319f5f5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 147 deletions.
2 changes: 1 addition & 1 deletion lib/photobooth/bloc/photobooth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<PhotoboothEvent, PhotoboothState> {
PhotoboothBloc([UuidGetter? uuid])
Expand Down
7 changes: 2 additions & 5 deletions lib/photobooth/view/photobooth_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -23,16 +24,13 @@ class PhotoboothPage extends StatelessWidget {
return AppPageRoute(builder: (_) => const PhotoboothPage());
}

static const String name = 'PhotoboothPage';

@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => PhotoboothBloc(),
child: Navigator(
onGenerateRoute: (_) => AppPageRoute(
builder: (_) => const PhotoboothView(),
settings: const RouteSettings(name: name),
),
),
);
Expand Down Expand Up @@ -91,8 +89,7 @@ class _PhotoboothViewState extends State<PhotoboothView> {
.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
Expand Down
5 changes: 3 additions & 2 deletions lib/share/view/share_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -79,8 +80,8 @@ class _ShareRetakeButton extends StatelessWidget {
);
if (confirmed) {
context.read<PhotoboothBloc>().add(const PhotoClearAllTapped());
Navigator.of(context).popUntil(
(route) => route.settings.name == PhotoboothPage.name,
unawaited(
Navigator.of(context).pushReplacement(PhotoboothPage.route()),
);
}
},
Expand Down
6 changes: 4 additions & 2 deletions lib/stickers/view/stickers_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ class _RetakeButton extends StatelessWidget {
);
if (confirmed) {
context.read<PhotoboothBloc>().add(const PhotoClearAllTapped());
Navigator.of(context).pop();
unawaited(
Navigator.of(context).pushReplacement(PhotoboothPage.route()),
);
}
},
message: l10n.retakeButtonTooltip,
Expand All @@ -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(
Expand Down
12 changes: 0 additions & 12 deletions test/photobooth/view/photobooth_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppTooltipButton>(retakeButtonFinder).onPressed();
await tester.pumpAndSettle();

tester.widget<ElevatedButton>(find.byType(ElevatedButton)).onPressed!();

await tester.pumpAndSettle();

expect(find.byType(PhotoboothView), findsOneWidget);
});
});

Expand Down
105 changes: 6 additions & 99 deletions test/share/view/share_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
Expand All @@ -409,51 +378,20 @@ void main() {
await tester.pumpAndSettle();

expect(retakeButtonFinder, findsOneWidget);
expect(find.byKey(photoboothPage), findsNothing);
expect(find.byType(PhotoboothPage), findsNothing);

verifyNever(() => photoboothBloc.add(PhotoClearAllTapped()));
});

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'),
);
Expand All @@ -470,51 +408,20 @@ void main() {
await tester.pumpAndSettle();

expect(retakeButtonFinder, findsOneWidget);
expect(find.byKey(photoboothPage), findsNothing);
expect(find.byType(PhotoboothPage), findsNothing);

verifyNever(() => photoboothBloc.add(PhotoClearAllTapped()));
});

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'),
);
Expand All @@ -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);
});
Expand Down
35 changes: 9 additions & 26 deletions test/stickers/view/stickers_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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',
Expand Down

0 comments on commit 319f5f5

Please sign in to comment.