From ca7a78b7834b8df52a7632bd6953a9d103a26f9b Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Fri, 14 Jul 2023 23:48:20 +0200 Subject: [PATCH] A few fixes in computation --- .../bottom_sheets/smooth_bottom_sheet.dart | 14 ++++++++++---- .../preferences/user_preferences_widgets.dart | 14 +++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/smooth_app/lib/generic_lib/bottom_sheets/smooth_bottom_sheet.dart b/packages/smooth_app/lib/generic_lib/bottom_sheets/smooth_bottom_sheet.dart index 370801d42266..06c03ee2a1b8 100644 --- a/packages/smooth_app/lib/generic_lib/bottom_sheets/smooth_bottom_sheet.dart +++ b/packages/smooth_app/lib/generic_lib/bottom_sheets/smooth_bottom_sheet.dart @@ -6,13 +6,18 @@ import 'package:smooth_app/generic_lib/design_constants.dart'; Future showSmoothModalSheet({ required BuildContext context, required WidgetBuilder builder, + double? minHeight, }) { return showModalBottomSheet( + constraints: + minHeight != null ? BoxConstraints(minHeight: minHeight) : null, + isScrollControlled: minHeight != null, context: context, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: ROUNDED_RADIUS), ), builder: builder, + useSafeArea: true, ); } @@ -27,7 +32,8 @@ Future showSmoothDraggableModalSheet({ context: context, borderRadius: const BorderRadius.vertical(top: ROUNDED_RADIUS), headerBuilder: (_) => header, - headerHeight: SmoothModalSheetHeader._computeHeight(context, header), + headerHeight: + SmoothModalSheetHeader.computeHeight(context, header.closeButton), bodyBuilder: bodyBuilder, ); } @@ -135,13 +141,13 @@ class SmoothModalSheetHeader extends StatelessWidget { ); } - static double _computeHeight( + static double computeHeight( BuildContext context, - SmoothModalSheetHeader header, + bool hasCloseButton, ) { double size = VERY_SMALL_SPACE * 2; - if (header.closeButton == true) { + if (hasCloseButton == true) { size += (MEDIUM_SPACE * 2) + (Theme.of(context).iconTheme.size ?? 20.0); } else { size += Theme.of(context).textTheme.titleLarge?.fontSize ?? 15.0; diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart index 9a2e851cc6b1..72aaf909fe0e 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart @@ -185,11 +185,17 @@ class UserPreferencesMultipleChoicesItem extends StatelessWidget { onTap: () async { final double itemHeight = (descriptions != null ? 15.0 : 0.0) + (5.0 * 2) + + 1.0 + (56.0 + Theme.of(context).visualDensity.baseSizeAdjustment.dy); + final MediaQueryData queryData = MediaQueryData.fromView( + WidgetsBinding.instance.platformDispatcher.implicitView!); + + // If there is not enough space, we use the scrolling sheet final T? res; - if (itemHeight * labels.length > - MediaQuery.of(context).size.height * 0.8) { + if ((itemHeight * labels.length + + SmoothModalSheetHeader.computeHeight(context, true)) > + (queryData.size.height * 0.9) - queryData.viewPadding.top) { res = await showSmoothDraggableModalSheet( context: context, header: SmoothModalSheetHeader(title: title), @@ -219,12 +225,14 @@ class UserPreferencesMultipleChoicesItem extends StatelessWidget { } else { res = await showSmoothModalSheet( context: context, + minHeight: SmoothModalSheetHeader.computeHeight(context, false) + + itemHeight * labels.length, builder: (BuildContext context) { return SmoothModalSheet( title: title, bodyPadding: EdgeInsets.zero, body: SizedBox( - height: (itemHeight + 1.0) * labels.length, + height: itemHeight * labels.length, child: ListView.separated( physics: const NeverScrollableScrollPhysics(), itemCount: labels.length,