@@ -92,7 +92,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
92
92
}
93
93
}
94
94
95
- bool _overflowOccurredDuringLayout = false ;
95
+ // Set during layout if overflow occurred on the main axis
96
+ double _overflow;
96
97
97
98
void setupParentData (RenderBox child) {
98
99
if (child.parentData is ! FlexBoxParentData )
@@ -325,6 +326,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
325
326
}
326
327
child = child.parentData.nextSibling;
327
328
}
329
+ _overflow = math.max (0.0 , - freeSpace);
330
+ freeSpace = math.max (0.0 , freeSpace);
328
331
329
332
// Steps 4-5. Distribute remaining space to flexible children.
330
333
double spacePerFlex = totalFlex > 0 ? (freeSpace / totalFlex) : 0.0 ;
@@ -362,7 +365,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
362
365
child = child.parentData.nextSibling;
363
366
}
364
367
365
- // Section 8.2: Axis Alignment using the justify-content property
368
+ // Section 8.2: Main Axis Alignment using the justify-content property
366
369
double remainingSpace = math.max (0.0 , freeSpace - usedSpace);
367
370
double leadingSpace;
368
371
double betweenSpace;
@@ -389,20 +392,16 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
389
392
break ;
390
393
}
391
394
392
- Size desiredSize;
393
395
switch (_direction) {
394
396
case FlexDirection .horizontal:
395
- desiredSize = new Size (mainSize, crossSize);
396
- size = constraints.constrain (desiredSize);
397
+ size = constraints.constrain (new Size (mainSize, crossSize));
397
398
crossSize = size.height;
398
399
break ;
399
400
case FlexDirection .vertical:
400
- desiredSize = new Size (crossSize, mainSize);
401
401
size = constraints.constrain (new Size (crossSize, mainSize));
402
402
crossSize = size.width;
403
403
break ;
404
404
}
405
- _overflowOccurredDuringLayout = desiredSize != size;
406
405
407
406
// Position elements
408
407
double childMainPosition = leadingSpace;
@@ -449,7 +448,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
449
448
}
450
449
451
450
void paint (PaintingCanvas canvas, Offset offset) {
452
- if (_overflowOccurredDuringLayout ) {
451
+ if (_overflow > 0 ) {
453
452
canvas.save ();
454
453
canvas.clipRect (offset & size);
455
454
defaultPaint (canvas, offset);
@@ -458,4 +457,26 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
458
457
defaultPaint (canvas, offset);
459
458
}
460
459
}
460
+
461
+ void debugPaintSize (PaintingCanvas canvas, Offset offset) {
462
+ super .debugPaintSize (canvas, offset);
463
+ if (_overflow <= 0 )
464
+ return ;
465
+
466
+ // Draw a red rectangle over the overflow area in debug mode
467
+ // You should be using a Clip if you want to clip your children
468
+ Paint paint = new Paint ()..color = const Color (0x7FFF0000 );
469
+ Rect overflowRect;
470
+ switch (direction) {
471
+ case FlexDirection .horizontal:
472
+ overflowRect = offset + new Offset (size.width, 0.0 ) &
473
+ new Size (_overflow, size.height);
474
+ break ;
475
+ case FlexDirection .vertical:
476
+ overflowRect = offset + new Offset (0.0 , size.height) &
477
+ new Size (size.width, _overflow);
478
+ break ;
479
+ }
480
+ canvas.drawRect (overflowRect, paint);
481
+ }
461
482
}
0 commit comments