diff --git a/sheet/lib/src/scrollable.dart b/sheet/lib/src/scrollable.dart index cfff31b..a9910c7 100644 --- a/sheet/lib/src/scrollable.dart +++ b/sheet/lib/src/scrollable.dart @@ -409,7 +409,7 @@ class SheetState extends State return newPhysics.shouldReload(oldPhysics); } - bool _shouldUpdatePosition(SheetScrollable oldWidget) { + bool _shouldUpdatePositionBasedOnPhysics(SheetScrollable oldWidget) { ScrollPhysics? newPhysics = widget.physics ?? widget.scrollBehavior?.getScrollPhysics(context); ScrollPhysics? oldPhysics = oldWidget.physics ?? @@ -424,6 +424,16 @@ class SheetState extends State return widget.controller?.runtimeType != oldWidget.controller?.runtimeType; } + bool _shouldUpdatePositionBasedOnInitialExtent(SheetScrollable oldWidget) { + return widget.initialExtent != oldWidget.initialExtent; + // return false; + } + + bool _shouldUpdatePosition(SheetScrollable oldWidget) { + return _shouldUpdatePositionBasedOnPhysics(oldWidget) || + _shouldUpdatePositionBasedOnInitialExtent(oldWidget); + } + @override void didUpdateWidget(SheetScrollable oldWidget) { super.didUpdateWidget(oldWidget); diff --git a/sheet/lib/src/sheet.dart b/sheet/lib/src/sheet.dart index 39d99ec..34ac824 100644 --- a/sheet/lib/src/sheet.dart +++ b/sheet/lib/src/sheet.dart @@ -1,6 +1,7 @@ // ignore_for_file: always_put_control_body_on_new_line import 'dart:math' as math; + import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:sheet/src/widgets/resizable_sheet.dart'; @@ -269,6 +270,7 @@ class Sheet extends StatelessWidget { minExtent: minExtent, maxExtent: maxExtent, fit: fit, + resizeable: resizable, child: Padding( padding: padding, child: ResizableSheetChild( @@ -535,6 +537,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { super.key, this.axisDirection = AxisDirection.down, required this.offset, + this.resizeable = false, this.minExtent, this.maxExtent, super.child, @@ -548,6 +551,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { final double? minExtent; final double? maxExtent; final SheetFit fit; + final bool resizeable; @override RenderSheetViewport createRenderObject(BuildContext context) { @@ -557,6 +561,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { clipBehavior: clipBehavior, minExtent: minExtent, maxExtent: maxExtent, + resizeable: resizeable, fit: fit, ); } @@ -587,12 +592,14 @@ class RenderSheetViewport extends RenderBox SheetFit fit = SheetFit.expand, double? minExtent, double? maxExtent, + bool? resizeable, }) : _axisDirection = axisDirection, _offset = offset, _fit = fit, _minExtent = minExtent, _maxExtent = maxExtent, _cacheExtent = cacheExtent, + _resizeable = resizeable ?? false, _clipBehavior = clipBehavior { this.child = child; } @@ -702,6 +709,14 @@ class RenderSheetViewport extends RenderBox } } + bool get resizeable => _resizeable; + bool _resizeable; + set resizeable(bool value) { + if (value == _resizeable) return; + _resizeable = value; + markNeedsLayout(); + } + double get _viewportExtent { assert(hasSize); switch (axis) { @@ -779,7 +794,13 @@ class RenderSheetViewport extends RenderBox void performLayout() { final BoxConstraints constraints = this.constraints; if (child == null) { - size = constraints.smallest; + if (resizeable) { + // Allows expanding the sheet to the maximum available space + size = constraints.biggest; + } else { + // Locks the sheet to the child size + size = constraints.smallest; + } } else { final bool expand = fit == SheetFit.expand; final double maxExtent = this.maxExtent ?? constraints.maxHeight; diff --git a/sheet/lib/src/widgets/resizable_sheet.dart b/sheet/lib/src/widgets/resizable_sheet.dart index 6f5dd82..18c5453 100644 --- a/sheet/lib/src/widgets/resizable_sheet.dart +++ b/sheet/lib/src/widgets/resizable_sheet.dart @@ -118,27 +118,15 @@ class RenderResizableSheetChildBox extends RenderShiftedBox { return; } - // The height of the child will be the maximun between the offset pixels + // The height of the child will be the maximum between the offset pixels // and the minExtent - final double extent = max(_offset.pixels, minExtent); - + final double extend = max(_offset.pixels, minExtent); child!.layout( - BoxConstraints( - maxHeight: extent, - minHeight: extent, - minWidth: constraints.minWidth, - maxWidth: constraints.maxWidth, - ), + constraints.copyWith(maxHeight: extend, minHeight: extend), parentUsesSize: true, ); - if (!constraints.hasTightHeight) { - size = Size( - child!.size.width, constraints.constrainHeight(child!.size.height)); - childParentData.offset = Offset.zero; - } else { - size = constraints.biggest; - childParentData.offset = Offset.zero; - } + size = constraints.biggest; + childParentData.offset = Offset.zero; } }