@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
9
9
import 'package:flutter/semantics.dart' ;
10
10
11
11
import 'box.dart' ;
12
+ import 'debug.dart' ;
12
13
import 'layer.dart' ;
13
14
import 'object.dart' ;
14
15
import 'sliver.dart' ;
@@ -1388,73 +1389,7 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat
1388
1389
1389
1390
@override
1390
1391
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));
1458
1393
return constraints.biggest;
1459
1394
}
1460
1395
@@ -1858,17 +1793,48 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta
1858
1793
late double _shrinkWrapExtent;
1859
1794
bool _hasVisualOverflow = false ;
1860
1795
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
+
1861
1827
@override
1862
1828
void performLayout () {
1863
1829
final BoxConstraints constraints = this .constraints;
1864
1830
if (firstChild == null ) {
1831
+ // Shrinkwrapping viewport only requires the cross axis to be bounded.
1832
+ assert (_debugCheckHasBoundedCrossAxis ());
1865
1833
switch (axis) {
1866
1834
case Axis .vertical:
1867
- assert (constraints.hasBoundedWidth);
1868
1835
size = Size (constraints.maxWidth, constraints.minHeight);
1869
1836
break ;
1870
1837
case Axis .horizontal:
1871
- assert (constraints.hasBoundedHeight);
1872
1838
size = Size (constraints.minWidth, constraints.maxHeight);
1873
1839
break ;
1874
1840
}
@@ -1882,14 +1848,14 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta
1882
1848
1883
1849
final double mainAxisExtent;
1884
1850
final double crossAxisExtent;
1851
+ // Shrinkwrapping viewport only requires the cross axis to be bounded.
1852
+ assert (_debugCheckHasBoundedCrossAxis ());
1885
1853
switch (axis) {
1886
1854
case Axis .vertical:
1887
- assert (constraints.hasBoundedWidth);
1888
1855
mainAxisExtent = constraints.maxHeight;
1889
1856
crossAxisExtent = constraints.maxWidth;
1890
1857
break ;
1891
1858
case Axis .horizontal:
1892
- assert (constraints.hasBoundedHeight);
1893
1859
mainAxisExtent = constraints.maxWidth;
1894
1860
crossAxisExtent = constraints.maxHeight;
1895
1861
break ;
0 commit comments