@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
99import 'package:flutter/semantics.dart' ;
1010
1111import 'box.dart' ;
12+ import 'debug.dart' ;
1213import 'layer.dart' ;
1314import 'object.dart' ;
1415import 'sliver.dart' ;
@@ -1388,73 +1389,7 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat
13881389
13891390 @override
13901391 Size computeDryLayout (BoxConstraints constraints) {
1391- assert (() {
1392- if (! constraints.hasBoundedHeight || ! constraints.hasBoundedWidth) {
1393- switch (axis) {
1394- case Axis .vertical:
1395- if (! constraints.hasBoundedHeight) {
1396- throw FlutterError .fromParts (< DiagnosticsNode > [
1397- ErrorSummary ('Vertical viewport was given unbounded height.' ),
1398- ErrorDescription (
1399- 'Viewports expand in the scrolling direction to fill their container. '
1400- 'In this case, a vertical viewport was given an unlimited amount of '
1401- 'vertical space in which to expand. This situation typically happens '
1402- 'when a scrollable widget is nested inside another scrollable widget.' ,
1403- ),
1404- ErrorHint (
1405- 'If this widget is always nested in a scrollable widget there '
1406- 'is no need to use a viewport because there will always be enough '
1407- 'vertical space for the children. In this case, consider using a '
1408- 'Column or Wrap instead. Otherwise, consider using a '
1409- 'CustomScrollView to concatenate arbitrary slivers into a '
1410- 'single scrollable.' ,
1411- ),
1412- ]);
1413- }
1414- if (! constraints.hasBoundedWidth) {
1415- throw FlutterError (
1416- 'Vertical viewport was given unbounded width.\n '
1417- 'Viewports expand in the cross axis to fill their container and '
1418- 'constrain their children to match their extent in the cross axis. '
1419- 'In this case, a vertical viewport was given an unlimited amount of '
1420- 'horizontal space in which to expand.' ,
1421- );
1422- }
1423- break ;
1424- case Axis .horizontal:
1425- if (! constraints.hasBoundedWidth) {
1426- throw FlutterError .fromParts (< DiagnosticsNode > [
1427- ErrorSummary ('Horizontal viewport was given unbounded width.' ),
1428- ErrorDescription (
1429- 'Viewports expand in the scrolling direction to fill their container. '
1430- 'In this case, a horizontal viewport was given an unlimited amount of '
1431- 'horizontal space in which to expand. This situation typically happens '
1432- 'when a scrollable widget is nested inside another scrollable widget.' ,
1433- ),
1434- ErrorHint (
1435- 'If this widget is always nested in a scrollable widget there '
1436- 'is no need to use a viewport because there will always be enough '
1437- 'horizontal space for the children. In this case, consider using a '
1438- 'Row or Wrap instead. Otherwise, consider using a '
1439- 'CustomScrollView to concatenate arbitrary slivers into a '
1440- 'single scrollable.' ,
1441- ),
1442- ]);
1443- }
1444- if (! constraints.hasBoundedHeight) {
1445- throw FlutterError (
1446- 'Horizontal viewport was given unbounded height.\n '
1447- 'Viewports expand in the cross axis to fill their container and '
1448- 'constrain their children to match their extent in the cross axis. '
1449- 'In this case, a horizontal viewport was given an unlimited amount of '
1450- 'vertical space in which to expand.' ,
1451- );
1452- }
1453- break ;
1454- }
1455- }
1456- return true ;
1457- }());
1392+ assert (debugCheckHasBoundedAxis (axis, constraints));
14581393 return constraints.biggest;
14591394 }
14601395
@@ -1858,17 +1793,48 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta
18581793 late double _shrinkWrapExtent;
18591794 bool _hasVisualOverflow = false ;
18601795
1796+ bool _debugCheckHasBoundedCrossAxis () {
1797+ assert (() {
1798+ switch (axis) {
1799+ case Axis .vertical:
1800+ if (! constraints.hasBoundedWidth) {
1801+ throw FlutterError (
1802+ 'Vertical viewport was given unbounded width.\n '
1803+ 'Viewports expand in the cross axis to fill their container and '
1804+ 'constrain their children to match their extent in the cross axis. '
1805+ 'In this case, a vertical shrinkwrapping viewport was given an '
1806+ 'unlimited amount of horizontal space in which to expand.' ,
1807+ );
1808+ }
1809+ break ;
1810+ case Axis .horizontal:
1811+ if (! constraints.hasBoundedHeight) {
1812+ throw FlutterError (
1813+ 'Horizontal viewport was given unbounded height.\n '
1814+ 'Viewports expand in the cross axis to fill their container and '
1815+ 'constrain their children to match their extent in the cross axis. '
1816+ 'In this case, a horizontal shrinkwrapping viewport was given an '
1817+ 'unlimited amount of vertical space in which to expand.' ,
1818+ );
1819+ }
1820+ break ;
1821+ }
1822+ return true ;
1823+ }());
1824+ return true ;
1825+ }
1826+
18611827 @override
18621828 void performLayout () {
18631829 final BoxConstraints constraints = this .constraints;
18641830 if (firstChild == null ) {
1831+ // Shrinkwrapping viewport only requires the cross axis to be bounded.
1832+ assert (_debugCheckHasBoundedCrossAxis ());
18651833 switch (axis) {
18661834 case Axis .vertical:
1867- assert (constraints.hasBoundedWidth);
18681835 size = Size (constraints.maxWidth, constraints.minHeight);
18691836 break ;
18701837 case Axis .horizontal:
1871- assert (constraints.hasBoundedHeight);
18721838 size = Size (constraints.minWidth, constraints.maxHeight);
18731839 break ;
18741840 }
@@ -1882,14 +1848,14 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta
18821848
18831849 final double mainAxisExtent;
18841850 final double crossAxisExtent;
1851+ // Shrinkwrapping viewport only requires the cross axis to be bounded.
1852+ assert (_debugCheckHasBoundedCrossAxis ());
18851853 switch (axis) {
18861854 case Axis .vertical:
1887- assert (constraints.hasBoundedWidth);
18881855 mainAxisExtent = constraints.maxHeight;
18891856 crossAxisExtent = constraints.maxWidth;
18901857 break ;
18911858 case Axis .horizontal:
1892- assert (constraints.hasBoundedHeight);
18931859 mainAxisExtent = constraints.maxWidth;
18941860 crossAxisExtent = constraints.maxHeight;
18951861 break ;
0 commit comments