Assaf Packin
Committed by GitHub

Allow resizing sheet larger than minResizableExtent when resizable is true (#411)

* include resizeable in sheet performLayout

* Update resize logic

---------

Co-authored-by: Hari07 <22373191+Hari-07@users.noreply.github.com>
@@ -409,7 +409,7 @@ class SheetState extends State<SheetScrollable> @@ -409,7 +409,7 @@ class SheetState extends State<SheetScrollable>
409 return newPhysics.shouldReload(oldPhysics); 409 return newPhysics.shouldReload(oldPhysics);
410 } 410 }
411 411
412 - bool _shouldUpdatePosition(SheetScrollable oldWidget) { 412 + bool _shouldUpdatePositionBasedOnPhysics(SheetScrollable oldWidget) {
413 ScrollPhysics? newPhysics = 413 ScrollPhysics? newPhysics =
414 widget.physics ?? widget.scrollBehavior?.getScrollPhysics(context); 414 widget.physics ?? widget.scrollBehavior?.getScrollPhysics(context);
415 ScrollPhysics? oldPhysics = oldWidget.physics ?? 415 ScrollPhysics? oldPhysics = oldWidget.physics ??
@@ -424,6 +424,16 @@ class SheetState extends State<SheetScrollable> @@ -424,6 +424,16 @@ class SheetState extends State<SheetScrollable>
424 return widget.controller?.runtimeType != oldWidget.controller?.runtimeType; 424 return widget.controller?.runtimeType != oldWidget.controller?.runtimeType;
425 } 425 }
426 426
  427 + bool _shouldUpdatePositionBasedOnInitialExtent(SheetScrollable oldWidget) {
  428 + return widget.initialExtent != oldWidget.initialExtent;
  429 + // return false;
  430 + }
  431 +
  432 + bool _shouldUpdatePosition(SheetScrollable oldWidget) {
  433 + return _shouldUpdatePositionBasedOnPhysics(oldWidget) ||
  434 + _shouldUpdatePositionBasedOnInitialExtent(oldWidget);
  435 + }
  436 +
427 @override 437 @override
428 void didUpdateWidget(SheetScrollable oldWidget) { 438 void didUpdateWidget(SheetScrollable oldWidget) {
429 super.didUpdateWidget(oldWidget); 439 super.didUpdateWidget(oldWidget);
1 // ignore_for_file: always_put_control_body_on_new_line 1 // ignore_for_file: always_put_control_body_on_new_line
2 2
3 import 'dart:math' as math; 3 import 'dart:math' as math;
  4 +
4 import 'package:flutter/material.dart'; 5 import 'package:flutter/material.dart';
5 import 'package:flutter/rendering.dart'; 6 import 'package:flutter/rendering.dart';
6 import 'package:sheet/src/widgets/resizable_sheet.dart'; 7 import 'package:sheet/src/widgets/resizable_sheet.dart';
@@ -269,6 +270,7 @@ class Sheet extends StatelessWidget { @@ -269,6 +270,7 @@ class Sheet extends StatelessWidget {
269 minExtent: minExtent, 270 minExtent: minExtent,
270 maxExtent: maxExtent, 271 maxExtent: maxExtent,
271 fit: fit, 272 fit: fit,
  273 + resizeable: resizable,
272 child: Padding( 274 child: Padding(
273 padding: padding, 275 padding: padding,
274 child: ResizableSheetChild( 276 child: ResizableSheetChild(
@@ -535,6 +537,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { @@ -535,6 +537,7 @@ class SheetViewport extends SingleChildRenderObjectWidget {
535 super.key, 537 super.key,
536 this.axisDirection = AxisDirection.down, 538 this.axisDirection = AxisDirection.down,
537 required this.offset, 539 required this.offset,
  540 + this.resizeable = false,
538 this.minExtent, 541 this.minExtent,
539 this.maxExtent, 542 this.maxExtent,
540 super.child, 543 super.child,
@@ -548,6 +551,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { @@ -548,6 +551,7 @@ class SheetViewport extends SingleChildRenderObjectWidget {
548 final double? minExtent; 551 final double? minExtent;
549 final double? maxExtent; 552 final double? maxExtent;
550 final SheetFit fit; 553 final SheetFit fit;
  554 + final bool resizeable;
551 555
552 @override 556 @override
553 RenderSheetViewport createRenderObject(BuildContext context) { 557 RenderSheetViewport createRenderObject(BuildContext context) {
@@ -557,6 +561,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { @@ -557,6 +561,7 @@ class SheetViewport extends SingleChildRenderObjectWidget {
557 clipBehavior: clipBehavior, 561 clipBehavior: clipBehavior,
558 minExtent: minExtent, 562 minExtent: minExtent,
559 maxExtent: maxExtent, 563 maxExtent: maxExtent,
  564 + resizeable: resizeable,
560 fit: fit, 565 fit: fit,
561 ); 566 );
562 } 567 }
@@ -587,12 +592,14 @@ class RenderSheetViewport extends RenderBox @@ -587,12 +592,14 @@ class RenderSheetViewport extends RenderBox
587 SheetFit fit = SheetFit.expand, 592 SheetFit fit = SheetFit.expand,
588 double? minExtent, 593 double? minExtent,
589 double? maxExtent, 594 double? maxExtent,
  595 + bool? resizeable,
590 }) : _axisDirection = axisDirection, 596 }) : _axisDirection = axisDirection,
591 _offset = offset, 597 _offset = offset,
592 _fit = fit, 598 _fit = fit,
593 _minExtent = minExtent, 599 _minExtent = minExtent,
594 _maxExtent = maxExtent, 600 _maxExtent = maxExtent,
595 _cacheExtent = cacheExtent, 601 _cacheExtent = cacheExtent,
  602 + _resizeable = resizeable ?? false,
596 _clipBehavior = clipBehavior { 603 _clipBehavior = clipBehavior {
597 this.child = child; 604 this.child = child;
598 } 605 }
@@ -702,6 +709,14 @@ class RenderSheetViewport extends RenderBox @@ -702,6 +709,14 @@ class RenderSheetViewport extends RenderBox
702 } 709 }
703 } 710 }
704 711
  712 + bool get resizeable => _resizeable;
  713 + bool _resizeable;
  714 + set resizeable(bool value) {
  715 + if (value == _resizeable) return;
  716 + _resizeable = value;
  717 + markNeedsLayout();
  718 + }
  719 +
705 double get _viewportExtent { 720 double get _viewportExtent {
706 assert(hasSize); 721 assert(hasSize);
707 switch (axis) { 722 switch (axis) {
@@ -779,7 +794,13 @@ class RenderSheetViewport extends RenderBox @@ -779,7 +794,13 @@ class RenderSheetViewport extends RenderBox
779 void performLayout() { 794 void performLayout() {
780 final BoxConstraints constraints = this.constraints; 795 final BoxConstraints constraints = this.constraints;
781 if (child == null) { 796 if (child == null) {
782 - size = constraints.smallest; 797 + if (resizeable) {
  798 + // Allows expanding the sheet to the maximum available space
  799 + size = constraints.biggest;
  800 + } else {
  801 + // Locks the sheet to the child size
  802 + size = constraints.smallest;
  803 + }
783 } else { 804 } else {
784 final bool expand = fit == SheetFit.expand; 805 final bool expand = fit == SheetFit.expand;
785 final double maxExtent = this.maxExtent ?? constraints.maxHeight; 806 final double maxExtent = this.maxExtent ?? constraints.maxHeight;
@@ -118,27 +118,15 @@ class RenderResizableSheetChildBox extends RenderShiftedBox { @@ -118,27 +118,15 @@ class RenderResizableSheetChildBox extends RenderShiftedBox {
118 return; 118 return;
119 } 119 }
120 120
121 - // The height of the child will be the maximun between the offset pixels 121 + // The height of the child will be the maximum between the offset pixels
122 // and the minExtent 122 // and the minExtent
123 - final double extent = max(_offset.pixels, minExtent);  
124 - 123 + final double extend = max(_offset.pixels, minExtent);
125 child!.layout( 124 child!.layout(
126 - BoxConstraints(  
127 - maxHeight: extent,  
128 - minHeight: extent,  
129 - minWidth: constraints.minWidth,  
130 - maxWidth: constraints.maxWidth,  
131 - ), 125 + constraints.copyWith(maxHeight: extend, minHeight: extend),
132 parentUsesSize: true, 126 parentUsesSize: true,
133 ); 127 );
134 128
135 - if (!constraints.hasTightHeight) {  
136 - size = Size(  
137 - child!.size.width, constraints.constrainHeight(child!.size.height));  
138 - childParentData.offset = Offset.zero;  
139 - } else {  
140 - size = constraints.biggest;  
141 - childParentData.offset = Offset.zero;  
142 - } 129 + size = constraints.biggest;
  130 + childParentData.offset = Offset.zero;
143 } 131 }
144 } 132 }