@@ -1014,6 +1014,13 @@ mixin _CupertinoSheetRouteTransitionMixin<T> on PageRoute<T> {
10141014 }
10151015}
10161016
1017+ // Reads the height from the render box instead of context.size, which throws
1018+ // in debug mode when the box is dirty for layout. A drag can end while a
1019+ // relayout is pending, and the last laid out height is the one the drag was
1020+ // made against.
1021+ double _sheetHeightOf (BuildContext context) =>
1022+ (context.findRenderObject ()! as RenderBox ).size.height;
1023+
10171024class _CupertinoDragGestureDetector <T > extends StatefulWidget {
10181025 const _CupertinoDragGestureDetector ({
10191026 required this .enabledCallback,
@@ -1040,11 +1047,6 @@ class _CupertinoDragGestureDetectorState<T> extends State<_CupertinoDragGestureD
10401047 static VelocityTracker _cupertinoVelocityBuilder (PointerEvent event) =>
10411048 IOSScrollViewFlingVelocityTracker (event.kind);
10421049
1043- // Reads the height from the render box instead of context.size, which asserts
1044- // when the box is dirty for layout. A drag can end while a relayout is
1045- // pending, and the last laid out height is the one the drag was made against.
1046- double get sheetHeight => (context.findRenderObject ()! as RenderBox ).size.height;
1047-
10481050 @override
10491051 void initState () {
10501052 super .initState ();
@@ -1092,6 +1094,7 @@ class _CupertinoDragGestureDetectorState<T> extends State<_CupertinoDragGestureD
10921094 if (_stretchDragController == null ) {
10931095 return ;
10941096 }
1097+ final double sheetHeight = _sheetHeightOf (context);
10951098 final double delta = sheetHeight > 0 ? details.primaryDelta! / sheetHeight : 0.0 ;
10961099 _dragGestureController! .dragUpdate (
10971100 // Divide by size of the sheet.
@@ -1107,6 +1110,7 @@ class _CupertinoDragGestureDetectorState<T> extends State<_CupertinoDragGestureD
11071110 _dragGestureController = null ;
11081111 return ;
11091112 }
1113+ final double sheetHeight = _sheetHeightOf (context);
11101114 final double velocity = sheetHeight > 0
11111115 ? details.velocity.pixelsPerSecond.dy / sheetHeight
11121116 : 0.0 ;
@@ -1450,13 +1454,10 @@ class _CupertinoDraggableScrollableSheetState<T>
14501454 _dragGestureController ?? = widget.onStartPopGesture ();
14511455 }
14521456
1453- // See _CupertinoDragGestureDetectorState.sheetHeight.
1454- double get _sheetHeight => (context.findRenderObject ()! as RenderBox ).size.height;
1455-
14561457 void _dragUpdate (double delta) {
14571458 assert (mounted);
14581459 if (_dragGestureController != null ) {
1459- final double sheetHeight = _sheetHeight ;
1460+ final double sheetHeight = _sheetHeightOf (context) ;
14601461 _dragGestureController! .dragUpdate (
14611462 delta / (sheetHeight - (sheetHeight * _kTopGapRatio)),
14621463 null ,
@@ -1467,7 +1468,7 @@ class _CupertinoDraggableScrollableSheetState<T>
14671468 void _handleDragEnd (double velocity) {
14681469 assert (mounted);
14691470 if (_dragGestureController != null ) {
1470- _dragGestureController! .dragEnd (- velocity / _sheetHeight , null );
1471+ _dragGestureController! .dragEnd (- velocity / _sheetHeightOf (context) , null );
14711472 _dragGestureController = null ;
14721473 }
14731474 }
0 commit comments