From 35a90ace0aad548a2c1530acaba324d295f17a55 Mon Sep 17 00:00:00 2001 From: otsmr Date: Sat, 6 Dec 2025 21:20:13 +0100 Subject: [PATCH] improve layout for smaller devices --- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../camera_preview.dart | 7 ++-- .../camera_preview_controller_view.dart | 3 +- .../views/camera/share_image_editor_view.dart | 2 +- lib/src/views/chats/media_viewer.view.dart | 2 +- .../views/components/media_view_sizing.dart | 37 ++++++++++++------- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index fa4cdb6..e3773d4 100644 --- a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -52,7 +52,7 @@ { return Container(); } return MediaViewSizing( - requiredHeight: 80, + requiredHeight: 0, + additionalPadding: 59, bottomNavigation: Container(), child: GestureDetector( onPanStart: (details) async { diff --git a/lib/src/views/camera/share_image_editor_view.dart b/lib/src/views/camera/share_image_editor_view.dart index 380f354..1e69bea 100644 --- a/lib/src/views/camera/share_image_editor_view.dart +++ b/lib/src/views/camera/share_image_editor_view.dart @@ -533,7 +533,7 @@ class _ShareImageEditorView extends State { setState(() {}); }, child: MediaViewSizing( - requiredHeight: 80, + requiredHeight: 59, bottomNavigation: ColoredBox( color: Theme.of(context).colorScheme.surface, child: Row( diff --git a/lib/src/views/chats/media_viewer.view.dart b/lib/src/views/chats/media_viewer.view.dart index 6be054e..20a440b 100644 --- a/lib/src/views/chats/media_viewer.view.dart +++ b/lib/src/views/chats/media_viewer.view.dart @@ -518,7 +518,7 @@ class _MediaViewerViewState extends State { }, child: MediaViewSizing( bottomNavigation: bottomNavigation(), - requiredHeight: 80, + requiredHeight: 55, child: Stack( children: [ if (videoController != null) diff --git a/lib/src/views/components/media_view_sizing.dart b/lib/src/views/components/media_view_sizing.dart index 46ed904..6510979 100644 --- a/lib/src/views/components/media_view_sizing.dart +++ b/lib/src/views/components/media_view_sizing.dart @@ -6,9 +6,11 @@ class MediaViewSizing extends StatefulWidget { super.key, this.requiredHeight, this.bottomNavigation, + this.additionalPadding, }); final double? requiredHeight; + final double? additionalPadding; final Widget? bottomNavigation; final Widget child; @@ -20,19 +22,22 @@ class _MediaViewSizingState extends State { @override Widget build(BuildContext context) { var needToDownSizeImage = false; + var availableHeight = MediaQuery.of(context).size.height; + // Get the screen size and safe area padding + final screenSize = MediaQuery.of(context).size; + final safeAreaPadding = MediaQuery.of(context).padding; + + // Calculate the available width and height + final availableWidth = screenSize.width; + availableHeight = screenSize.height - + safeAreaPadding.top - + safeAreaPadding.bottom - + (widget.additionalPadding ?? 0); + + final aspectRatioWidth = availableWidth; + final aspectRatioHeight = (aspectRatioWidth * 16) / 9; if (widget.requiredHeight != null) { - // Get the screen size and safe area padding - final screenSize = MediaQuery.of(context).size; - final safeAreaPadding = MediaQuery.of(context).padding; - - // Calculate the available width and height - final availableWidth = screenSize.width; - final availableHeight = - screenSize.height - safeAreaPadding.top - safeAreaPadding.bottom; - - final aspectRatioWidth = availableWidth; - final aspectRatioHeight = (aspectRatioWidth * 16) / 9; if (aspectRatioHeight < availableHeight) { if ((screenSize.height - widget.requiredHeight!) < aspectRatioHeight) { needToDownSizeImage = true; @@ -43,6 +48,7 @@ class _MediaViewSizingState extends State { Widget imageChild = Align( alignment: Alignment.topCenter, child: SizedBox( + height: availableHeight, child: AspectRatio( aspectRatio: 9 / 16, child: ClipRRect( @@ -68,8 +74,13 @@ class _MediaViewSizingState extends State { } return SafeArea( - child: Column( - children: [imageChild, bottomNavigation], + child: Container( + constraints: BoxConstraints( + maxHeight: availableHeight, + ), + child: Column( + children: [imageChild, bottomNavigation], + ), ), ); }