Skip to content

Commit

Permalink
Nutrition facts array as a bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jul 22, 2023
1 parent ef15cab commit 9ebc333
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Future<T?> showSmoothDraggableModalSheet<T>({

/// You must return a Sliver Widget
required WidgetBuilder bodyBuilder,
double? initHeight,
}) {
return showDraggableModalSheet<T>(
context: context,
Expand All @@ -35,6 +36,7 @@ Future<T?> showSmoothDraggableModalSheet<T>({
headerHeight:
SmoothModalSheetHeader.computeHeight(context, header.closeButton),
bodyBuilder: bodyBuilder,
initHeight: 0.7,
);
}

Expand Down
51 changes: 31 additions & 20 deletions packages/smooth_app/lib/pages/product/portion_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/generic_lib/bottom_sheets/smooth_bottom_sheet.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/duration_constants.dart';
import 'package:smooth_app/pages/product/ordered_nutrients_cache.dart';
import 'package:smooth_app/pages/product/portion_helper.dart';
Expand Down Expand Up @@ -167,28 +167,39 @@ class _PortionCalculatorState extends State<PortionCalculator> {
if (helper.isEmpty) {
return;
}
await showDialog<void>(
await showSmoothDraggableModalSheet<void>(
context: context,
builder: (final BuildContext context) => SmoothAlertDialog(
header: SmoothModalSheetHeader(
title: appLocalizations.portion_calculator_result_title(quantity),
body: Column(
children: List<Widget>.generate(
helper.length,
(final int index) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(helper.getName(index)),
Text(helper.getValue(index)),
],
),
),
),
positiveAction: SmoothActionButton(
text: appLocalizations.okay,
onPressed: () => Navigator.of(context).pop(),
),
),
bodyBuilder: (BuildContext context) {
return SliverList(
delegate: SliverChildBuilderDelegate(
childCount: helper.length,
(BuildContext context, int position) {
return Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(
horizontal: VERY_LARGE_SPACE,
vertical: LARGE_SPACE,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(helper.getName(position)),
Text(helper.getValue(position)),
],
),
),
if (position < helper.length - 1) const Divider(height: 1.0)
],
);
},
),
);
},
);
}

Expand Down

0 comments on commit 9ebc333

Please sign in to comment.