diff --git a/lib/stickers/widgets/stickers_drawer_layer/mobile_stickers_drawer.dart b/lib/stickers/widgets/stickers_drawer_layer/mobile_stickers_drawer.dart index 0bdfa4ed..4f196889 100644 --- a/lib/stickers/widgets/stickers_drawer_layer/mobile_stickers_drawer.dart +++ b/lib/stickers/widgets/stickers_drawer_layer/mobile_stickers_drawer.dart @@ -14,8 +14,12 @@ class MobileStickersDrawer extends StatelessWidget { @override Widget build(BuildContext context) { final l10n = context.l10n; + final screenHeight = MediaQuery.of(context).size.height; return Container( margin: const EdgeInsets.only(top: 30), + height: screenHeight < PhotoboothBreakpoints.small + ? screenHeight + : screenHeight * 0.75, decoration: const BoxDecoration( color: PhotoboothColors.white, borderRadius: BorderRadius.vertical(top: Radius.circular(12)), diff --git a/lib/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer.dart b/lib/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer.dart index dd943237..4592f9be 100644 --- a/lib/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer.dart +++ b/lib/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer.dart @@ -3,25 +3,17 @@ 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:platform_helper/platform_helper.dart'; class StickersDrawerLayer extends StatelessWidget { - StickersDrawerLayer({ - Key? key, - PlatformHelper? platformHelper, - }) : platformHelper = platformHelper ?? PlatformHelper(), - super(key: key); - - final PlatformHelper platformHelper; + StickersDrawerLayer({Key? key}) : super(key: key); @override Widget build(BuildContext context) { - final orientation = MediaQuery.of(context).orientation; return BlocConsumer( listenWhen: (previous, current) => current.isDrawerActive && current != previous, listener: (context, state) { - if (platformHelper.isMobile || orientation == Orientation.portrait) { + if (MediaQuery.of(context).size.width < PhotoboothBreakpoints.small) { showModalBottomSheet( context: context, barrierColor: PhotoboothColors.black.withOpacity(0.75), @@ -36,9 +28,10 @@ class StickersDrawerLayer extends StatelessWidget { context.read().add(const StickersDrawerToggled()); } }, - buildWhen: (previous, current) => !isMobile && current != previous, + buildWhen: (previous, current) => current != previous, builder: (context, state) { - if (orientation == Orientation.landscape && state.isDrawerActive) + if (MediaQuery.of(context).size.width >= PhotoboothBreakpoints.small && + state.isDrawerActive) return const Positioned( right: 0, top: 0, diff --git a/test/helpers/set_display_size.dart b/test/helpers/set_display_size.dart index ae42019e..e0a324d5 100644 --- a/test/helpers/set_display_size.dart +++ b/test/helpers/set_display_size.dart @@ -22,4 +22,8 @@ extension PhotoboothWidgetTester on WidgetTester { void setPortraitDisplaySize() { setDisplaySize(const Size(PhotoboothBreakpoints.small, 1000)); } + + void setSmallDisplaySize() { + setDisplaySize(const Size(PhotoboothBreakpoints.small - 1, 1000)); + } } diff --git a/test/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer_test.dart b/test/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer_test.dart index 11eb8702..35949e8e 100644 --- a/test/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer_test.dart +++ b/test/stickers/widgets/stickers_drawer_layer/stickers_drawer_layer_test.dart @@ -7,7 +7,6 @@ import 'package:io_photobooth/assets.g.dart'; import 'package:io_photobooth/photobooth/photobooth.dart'; import 'package:io_photobooth/stickers/stickers.dart'; import 'package:mocktail/mocktail.dart'; -import 'package:platform_helper/platform_helper.dart'; import '../../../helpers/helpers.dart'; @@ -25,8 +24,6 @@ class FakePhotoboothState extends Fake implements PhotoboothState {} class MockPhotoboothBloc extends MockBloc implements PhotoboothBloc {} -class MockPlatformHelper extends Mock implements PlatformHelper {} - void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -39,24 +36,19 @@ void main() { group('StickersDrawerLayer', () { late PhotoboothBloc photoboothBloc; late StickersBloc stickersBloc; - late PlatformHelper platformHelper; setUp(() { photoboothBloc = MockPhotoboothBloc(); stickersBloc = MockStickersBloc(); - platformHelper = MockPlatformHelper(); }); group('DesktopStickersDrawer', () { testWidgets( - 'renders DesktopStickersDrawer when ' - 'is not mobile, mode is active and orientation is landscape', - (tester) async { - when(() => platformHelper.isMobile).thenReturn(false); + 'does not render DesktopStickersDrawer when ' + 'drawer is inactive', (tester) async { when(() => stickersBloc.state).thenReturn( - StickersState(isDrawerActive: true), + StickersState(isDrawerActive: false), ); - tester.setLandscapeDisplaySize(); await tester.pumpApp( BlocProvider.value( value: stickersBloc, @@ -64,15 +56,15 @@ void main() { ), photoboothBloc: photoboothBloc, ); - expect(find.byType(DesktopStickersDrawer), findsOneWidget); + expect(find.byType(DesktopStickersDrawer), findsNothing); }); testWidgets( - 'does not render DesktopStickersDrawer when ' - 'is not mobile, and mode is inactive', (tester) async { - when(() => platformHelper.isMobile).thenReturn(false); + 'renders DesktopStickersDrawer when ' + 'width greater than mobile breakpoint and it is drawer active', + (tester) async { when(() => stickersBloc.state).thenReturn( - StickersState(isDrawerActive: false), + StickersState(isDrawerActive: true), ); tester.setLandscapeDisplaySize(); await tester.pumpApp( @@ -82,17 +74,16 @@ void main() { ), photoboothBloc: photoboothBloc, ); - expect(find.byType(DesktopStickersDrawer), findsNothing); + expect(find.byType(DesktopStickersDrawer), findsOneWidget); }); testWidgets( 'does not render DesktopStickersDrawer when ' - 'is not mobile, and orientation is portrait', (tester) async { - when(() => platformHelper.isMobile).thenReturn(false); + 'width smaller than mobile and it is drawer active', (tester) async { when(() => stickersBloc.state).thenReturn( StickersState(isDrawerActive: true), ); - tester.setPortraitDisplaySize(); + tester.setSmallDisplaySize(); await tester.pumpApp( BlocProvider.value( value: stickersBloc, @@ -106,7 +97,6 @@ void main() { testWidgets('adds StickerSelected when StickerChoice tapped', (tester) async { final sticker = Assets.props.first; - when(() => platformHelper.isMobile).thenReturn(false); when(() => stickersBloc.state).thenReturn( StickersState(isDrawerActive: true), ); @@ -148,14 +138,13 @@ void main() { group('MobileStickersDrawer', () { testWidgets( 'opens MobileStickersDrawer when ' - 'is mobile, is active and is portrait', (tester) async { - when(() => platformHelper.isMobile).thenReturn(true); + 'is active and width smaller than mobile breakpoint', (tester) async { whenListen( stickersBloc, Stream.fromIterable([StickersState(isDrawerActive: true)]), initialState: StickersState(isDrawerActive: false), ); - tester.setPortraitDisplaySize(); + tester.setSmallDisplaySize(); await tester.pumpApp( BlocProvider.value(value: stickersBloc, child: StickersDrawerLayer()), @@ -169,25 +158,27 @@ void main() { }); testWidgets( - 'opens MobileStickersDrawer when ' - 'is not mobile and is portrait', (tester) async { - when(() => platformHelper.isMobile).thenReturn(false); + 'does not open MobileStickersDrawer when ' + 'width greater than mobile breakpoint', (tester) async { whenListen( stickersBloc, Stream.fromIterable([StickersState(isDrawerActive: true)]), initialState: StickersState(isDrawerActive: false), ); - tester.setPortraitDisplaySize(); + tester.setLandscapeDisplaySize(); await tester.pumpApp( - BlocProvider.value(value: stickersBloc, child: StickersDrawerLayer()), + BlocProvider.value( + value: stickersBloc, + child: Scaffold(body: Stack(children: [StickersDrawerLayer()])), + ), photoboothBloc: photoboothBloc, ); await tester.pump(); - expect(find.byType(MobileStickersDrawer), findsOneWidget); + expect(find.byType(MobileStickersDrawer), findsNothing); tester.widget(find.byType(IconButton)).onPressed!(); - await tester.pumpAndSettle(); + await tester.pump(); }); testWidgets('can select stickers on MobileStickersDrawer', @@ -200,6 +191,8 @@ void main() { ]), initialState: StickersState(isDrawerActive: false), ); + tester.setSmallDisplaySize(); + await tester.pumpApp( BlocProvider.value(value: stickersBloc, child: StickersDrawerLayer()), photoboothBloc: photoboothBloc, @@ -220,6 +213,8 @@ void main() { Stream.fromIterable([StickersState(isDrawerActive: true)]), initialState: StickersState(isDrawerActive: false), ); + tester.setSmallDisplaySize(); + await tester.pumpApp( BlocProvider.value( value: stickersBloc,