From 5237213f9f52a178994638933fc510488344f4aa Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Sat, 10 Apr 2021 23:29:39 +1000 Subject: [PATCH 1/2] feature: Add constrainToVisibleArea field to SheetSizeFill [1/2] --- lib/src/sheet_size_behaviors.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/src/sheet_size_behaviors.dart b/lib/src/sheet_size_behaviors.dart index d1fb1b0..2ea68a7 100644 --- a/lib/src/sheet_size_behaviors.dart +++ b/lib/src/sheet_size_behaviors.dart @@ -4,7 +4,14 @@ abstract class SheetSizeBehavior { /// Fills the available hight in a sheet. class SheetSizeFill implements SheetSizeBehavior { - const SheetSizeFill(); + /// If set to `true`, the [SnappingSheetContent.child] will be constrained + /// to the sheet's visible area as it expands. + /// + /// Otherwise, it will be constrained to the maximum size that the sheet can + /// expand to, and clipped. + final bool constrainToVisibleArea; + + const SheetSizeFill({this.constrainToVisibleArea = true}); } /// Make the sheet have a static height. From 570c4c7f25a73516d1c1882ab73878526ae7e910 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Sun, 11 Apr 2021 00:23:59 +1000 Subject: [PATCH 2/2] feature: Allow constraining sheet content to the maximum expanded size [2/2] --- lib/src/sheet_content_wrapper.dart | 3 ++- lib/src/snapping_sheet_content.dart | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/src/sheet_content_wrapper.dart b/lib/src/sheet_content_wrapper.dart index f41dc91..7e28a12 100644 --- a/lib/src/sheet_content_wrapper.dart +++ b/lib/src/sheet_content_wrapper.dart @@ -66,7 +66,8 @@ class _SheetContentWrapperState extends State { Widget build(BuildContext context) { if (widget.sheetData == null) return SizedBox(); return widget.sizeCalculator.positionWidget( - child: _wrapWithNecessaryWidgets(widget.sheetData!.child), + child: _wrapWithNecessaryWidgets(widget.sheetData! + .buildConstrainedChild(widget.sizeCalculator.maxHeight)), ); } } diff --git a/lib/src/snapping_sheet_content.dart b/lib/src/snapping_sheet_content.dart index bbf53d5..c23a4a7 100644 --- a/lib/src/snapping_sheet_content.dart +++ b/lib/src/snapping_sheet_content.dart @@ -33,14 +33,22 @@ class SnappingSheetContent { this.childScrollController, }) : this._child = child; - double? _getHeight() { + double? _getHeight(double maxHeight) { var sizeBehavior = this.sizeBehavior; if (sizeBehavior is SheetSizeStatic) return sizeBehavior.height; + if (sizeBehavior is SheetSizeFill && !sizeBehavior.constrainToVisibleArea) + return maxHeight; } - Widget get child { - return SizedBox( - height: _getHeight(), + Widget buildConstrainedChild(double maxHeight) { + assert(location != SheetLocation.unknown, + 'The location must be known to constrain the child!'); + return OverflowBox( + alignment: location == SheetLocation.above + ? Alignment.bottomCenter + : Alignment.topCenter, + minHeight: _getHeight(maxHeight), + maxHeight: _getHeight(maxHeight), child: this._child, ); }