Skip to content

Commit

Permalink
A few fixes in computation
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jul 14, 2023
1 parent 281b825 commit ca7a78b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import 'package:smooth_app/generic_lib/design_constants.dart';
Future<T?> showSmoothModalSheet<T>({
required BuildContext context,
required WidgetBuilder builder,
double? minHeight,
}) {
return showModalBottomSheet<T>(
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,
);
}

Expand All @@ -27,7 +32,8 @@ Future<T?> showSmoothDraggableModalSheet<T>({
context: context,
borderRadius: const BorderRadius.vertical(top: ROUNDED_RADIUS),
headerBuilder: (_) => header,
headerHeight: SmoothModalSheetHeader._computeHeight(context, header),
headerHeight:
SmoothModalSheetHeader.computeHeight(context, header.closeButton),
bodyBuilder: bodyBuilder,
);
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,17 @@ class UserPreferencesMultipleChoicesItem<T> 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<T>(
context: context,
header: SmoothModalSheetHeader(title: title),
Expand Down Expand Up @@ -219,12 +225,14 @@ class UserPreferencesMultipleChoicesItem<T> extends StatelessWidget {
} else {
res = await showSmoothModalSheet<T>(
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,
Expand Down

0 comments on commit ca7a78b

Please sign in to comment.