Skip to content

Commit

Permalink
Allow resizing sheet larger than minResizableExtent when resizable is…
Browse files Browse the repository at this point in the history
… true (#411)

* include resizeable in sheet performLayout

* Update resize logic

---------

Co-authored-by: Hari07 <[email protected]>
  • Loading branch information
apackin and Hari-07 authored Nov 18, 2024
1 parent ac1ddc8 commit 208300a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
12 changes: 11 additions & 1 deletion sheet/lib/src/scrollable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class SheetState extends State<SheetScrollable>
return newPhysics.shouldReload(oldPhysics);
}

bool _shouldUpdatePosition(SheetScrollable oldWidget) {
bool _shouldUpdatePositionBasedOnPhysics(SheetScrollable oldWidget) {
ScrollPhysics? newPhysics =
widget.physics ?? widget.scrollBehavior?.getScrollPhysics(context);
ScrollPhysics? oldPhysics = oldWidget.physics ??
Expand All @@ -424,6 +424,16 @@ class SheetState extends State<SheetScrollable>
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);
Expand Down
23 changes: 22 additions & 1 deletion sheet/lib/src/sheet.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -269,6 +270,7 @@ class Sheet extends StatelessWidget {
minExtent: minExtent,
maxExtent: maxExtent,
fit: fit,
resizeable: resizable,
child: Padding(
padding: padding,
child: ResizableSheetChild(
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -557,6 +561,7 @@ class SheetViewport extends SingleChildRenderObjectWidget {
clipBehavior: clipBehavior,
minExtent: minExtent,
maxExtent: maxExtent,
resizeable: resizeable,
fit: fit,
);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 5 additions & 17 deletions sheet/lib/src/widgets/resizable_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 208300a

Please sign in to comment.