flex.dart 45.9 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math' as math;

7 8
import 'package:flutter/foundation.dart';

9
import 'box.dart';
10
import 'debug_overflow_indicator.dart';
11
import 'layer.dart';
12
import 'layout_helper.dart';
13
import 'object.dart';
14

Adam Barth's avatar
Adam Barth committed
15
/// How the child is inscribed into the available space.
16 17 18 19 20 21 22
///
/// See also:
///
///  * [RenderFlex], the flex render object.
///  * [Column], [Row], and [Flex], the flex widgets.
///  * [Expanded], the widget equivalent of [tight].
///  * [Flexible], the widget equivalent of [loose].
Adam Barth's avatar
Adam Barth committed
23 24
enum FlexFit {
  /// The child is forced to fill the available space.
25 26
  ///
  /// The [Expanded] widget assigns this kind of [FlexFit] to its child.
Adam Barth's avatar
Adam Barth committed
27 28 29 30
  tight,

  /// The child can be at most as large as the available space (but is
  /// allowed to be smaller).
31 32
  ///
  /// The [Flexible] widget assigns this kind of [FlexFit] to its child.
Adam Barth's avatar
Adam Barth committed
33 34 35
  loose,
}

Adam Barth's avatar
Adam Barth committed
36
/// Parent data for use with [RenderFlex].
37
class FlexParentData extends ContainerBoxParentData<RenderBox> {
38
  /// The flex factor to use for this child.
39
  ///
Adam Barth's avatar
Adam Barth committed
40 41 42 43
  /// If null or zero, the child is inflexible and determines its own size. If
  /// non-zero, the amount of space the child's can occupy in the main axis is
  /// determined by dividing the free space (after placing the inflexible
  /// children) according to the flex factors of the flexible children.
44
  int? flex;
45

Adam Barth's avatar
Adam Barth committed
46 47 48 49 50 51 52
  /// How a flexible child is inscribed into the available space.
  ///
  /// If [flex] is non-zero, the [fit] determines whether the child fills the
  /// space the parent makes available during layout. If the fit is
  /// [FlexFit.tight], the child is required to fill the available space. If the
  /// fit is [FlexFit.loose], the child can be at most as large as the available
  /// space (but is allowed to be smaller).
53
  FlexFit? fit;
Adam Barth's avatar
Adam Barth committed
54

55
  @override
56
  String toString() => '${super.toString()}; flex=$flex; fit=$fit';
57 58
}

59
/// How much space should be occupied in the main axis.
60 61 62 63
///
/// During a flex layout, available space along the main axis is allocated to
/// children. After allocating space, there might be some remaining free space.
/// This value controls whether to maximize or minimize the amount of free
64
/// space, subject to the incoming layout constraints.
65
///
66 67 68 69 70 71 72
/// See also:
///
///  * [Column], [Row], and [Flex], the flex widgets.
///  * [Expanded] and [Flexible], the widgets that controls a flex widgets'
///    children's flex.
///  * [RenderFlex], the flex render object.
///  * [MainAxisAlignment], which controls how the free space is distributed.
73
enum MainAxisSize {
74 75 76 77 78 79
  /// Minimize the amount of free space along the main axis, subject to the
  /// incoming layout constraints.
  ///
  /// If the incoming layout constraints have a large enough
  /// [BoxConstraints.minWidth] or [BoxConstraints.minHeight], there might still
  /// be a non-zero amount of free space.
80 81 82 83 84
  ///
  /// If the incoming layout constraints are unbounded, and any children have a
  /// non-zero [FlexParentData.flex] and a [FlexFit.tight] fit (as applied by
  /// [Expanded]), the [RenderFlex] will assert, because there would be infinite
  /// remaining free space and boxes cannot be given infinite size.
85 86
  min,

87 88 89 90 91 92
  /// Maximize the amount of free space along the main axis, subject to the
  /// incoming layout constraints.
  ///
  /// If the incoming layout constraints have a small enough
  /// [BoxConstraints.maxWidth] or [BoxConstraints.maxHeight], there might still
  /// be no free space.
93 94 95 96
  ///
  /// If the incoming layout constraints are unbounded, the [RenderFlex] will
  /// assert, because there would be infinite remaining free space and boxes
  /// cannot be given infinite size.
97 98 99
  max,
}

100
/// How the children should be placed along the main axis in a flex layout.
101 102 103 104 105
///
/// See also:
///
///  * [Column], [Row], and [Flex], the flex widgets.
///  * [RenderFlex], the flex render object.
106
enum MainAxisAlignment {
107
  /// Place the children as close to the start of the main axis as possible.
108 109 110 111 112 113
  ///
  /// If this value is used in a horizontal direction, a [TextDirection] must be
  /// available to determine if the start is the left or the right.
  ///
  /// If this value is used in a vertical direction, a [VerticalDirection] must be
  /// available to determine if the start is the top or the bottom.
114
  start,
115 116

  /// Place the children as close to the end of the main axis as possible.
117 118 119 120 121 122
  ///
  /// If this value is used in a horizontal direction, a [TextDirection] must be
  /// available to determine if the end is the left or the right.
  ///
  /// If this value is used in a vertical direction, a [VerticalDirection] must be
  /// available to determine if the end is the top or the bottom.
123
  end,
124 125

  /// Place the children as close to the middle of the main axis as possible.
126
  center,
127 128

  /// Place the free space evenly between the children.
129
  spaceBetween,
130

Adam Barth's avatar
Adam Barth committed
131 132
  /// Place the free space evenly between the children as well as half of that
  /// space before and after the first and last child.
133
  spaceAround,
134

Adam Barth's avatar
Adam Barth committed
135 136 137
  /// Place the free space evenly between the children as well as before and
  /// after the first and last child.
  spaceEvenly,
138 139
}

140
/// How the children should be placed along the cross axis in a flex layout.
141 142 143 144 145
///
/// See also:
///
///  * [Column], [Row], and [Flex], the flex widgets.
///  * [RenderFlex], the flex render object.
146
enum CrossAxisAlignment {
147 148 149
  /// Place the children with their start edge aligned with the start side of
  /// the cross axis.
  ///
150 151 152 153 154 155 156 157 158
  /// For example, in a column (a flex with a vertical axis) whose
  /// [TextDirection] is [TextDirection.ltr], this aligns the left edge of the
  /// children along the left edge of the column.
  ///
  /// If this value is used in a horizontal direction, a [TextDirection] must be
  /// available to determine if the start is the left or the right.
  ///
  /// If this value is used in a vertical direction, a [VerticalDirection] must be
  /// available to determine if the start is the top or the bottom.
159
  start,
160 161

  /// Place the children as close to the end of the cross axis as possible.
162
  ///
163 164 165 166 167 168 169 170 171
  /// For example, in a column (a flex with a vertical axis) whose
  /// [TextDirection] is [TextDirection.ltr], this aligns the right edge of the
  /// children along the right edge of the column.
  ///
  /// If this value is used in a horizontal direction, a [TextDirection] must be
  /// available to determine if the end is the left or the right.
  ///
  /// If this value is used in a vertical direction, a [VerticalDirection] must be
  /// available to determine if the end is the top or the bottom.
172
  end,
173

174 175 176 177
  /// Place the children so that their centers align with the middle of the
  /// cross axis.
  ///
  /// This is the default cross-axis alignment.
178
  center,
179 180

  /// Require the children to fill the cross axis.
181 182 183
  ///
  /// This causes the constraints passed to the children to be tight in the
  /// cross axis.
184
  stretch,
185 186

  /// Place the children along the cross axis such that their baselines match.
187
  ///
188 189 190 191 192 193 194 195 196 197
  /// Because baselines are always horizontal, this alignment is intended for
  /// horizontal main axes. If the main axis is vertical, then this value is
  /// treated like [start].
  ///
  /// For horizontal main axes, if the minimum height constraint passed to the
  /// flex layout exceeds the intrinsic height of the cross axis, children will
  /// be aligned as close to the top as they can be while honoring the baseline
  /// alignment. In other words, the extra space will be below all the children.
  ///
  /// Children who report no baseline will be top-aligned.
198
  baseline,
199 200
}

201
bool? _startIsTopLeft(Axis direction, TextDirection? textDirection, VerticalDirection? verticalDirection) {
202 203 204 205 206 207 208 209 210
  assert(direction != null);
  // If the relevant value of textDirection or verticalDirection is null, this returns null too.
  switch (direction) {
    case Axis.horizontal:
      switch (textDirection) {
        case TextDirection.ltr:
          return true;
        case TextDirection.rtl:
          return false;
211 212
        case null:
          return null;
213 214 215 216 217 218 219
      }
    case Axis.vertical:
      switch (verticalDirection) {
        case VerticalDirection.down:
          return true;
        case VerticalDirection.up:
          return false;
220 221
        case null:
          return null;
222 223 224 225
      }
  }
}

226
typedef _ChildSizingFunction = double Function(RenderBox child, double extent);
227

228
/// Displays its children in a one-dimensional array.
229
///
230 231 232 233 234 235
/// ## Layout algorithm
///
/// _This section describes how the framework causes [RenderFlex] to position
/// its children._
/// _See [BoxConstraints] for an introduction to box layout models._
///
236
/// Layout for a [RenderFlex] proceeds in six steps:
237
///
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
/// 1. Layout each child a null or zero flex factor with unbounded main axis
///    constraints and the incoming cross axis constraints. If the
///    [crossAxisAlignment] is [CrossAxisAlignment.stretch], instead use tight
///    cross axis constraints that match the incoming max extent in the cross
///    axis.
/// 2. Divide the remaining main axis space among the children with non-zero
///    flex factors according to their flex factor. For example, a child with a
///    flex factor of 2.0 will receive twice the amount of main axis space as a
///    child with a flex factor of 1.0.
/// 3. Layout each of the remaining children with the same cross axis
///    constraints as in step 1, but instead of using unbounded main axis
///    constraints, use max axis constraints based on the amount of space
///    allocated in step 2. Children with [Flexible.fit] properties that are
///    [FlexFit.tight] are given tight constraints (i.e., forced to fill the
///    allocated space), and children with [Flexible.fit] properties that are
///    [FlexFit.loose] are given loose constraints (i.e., not forced to fill the
///    allocated space).
/// 4. The cross axis extent of the [RenderFlex] is the maximum cross axis
///    extent of the children (which will always satisfy the incoming
///    constraints).
/// 5. The main axis extent of the [RenderFlex] is determined by the
///    [mainAxisSize] property. If the [mainAxisSize] property is
///    [MainAxisSize.max], then the main axis extent of the [RenderFlex] is the
///    max extent of the incoming main axis constraints. If the [mainAxisSize]
///    property is [MainAxisSize.min], then the main axis extent of the [Flex]
///    is the sum of the main axis extents of the children (subject to the
///    incoming constraints).
/// 6. Determine the position for each child according to the
///    [mainAxisAlignment] and the [crossAxisAlignment]. For example, if the
///    [mainAxisAlignment] is [MainAxisAlignment.spaceBetween], any main axis
///    space that has not been allocated to children is divided evenly and
///    placed between the children.
270 271 272 273 274
///
/// See also:
///
///  * [Flex], the widget equivalent.
///  * [Row] and [Column], direction-specific variants of [Flex].
275
class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, FlexParentData>,
276 277
                                        RenderBoxContainerDefaultsMixin<RenderBox, FlexParentData>,
                                        DebugOverflowIndicatorMixin {
278 279 280 281
  /// Creates a flex render object.
  ///
  /// By default, the flex layout is horizontal and children are aligned to the
  /// start of the main axis and the center of the cross axis.
282
  RenderFlex({
283
    List<RenderBox>? children,
284 285 286 287
    Axis direction = Axis.horizontal,
    MainAxisSize mainAxisSize = MainAxisSize.max,
    MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
    CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
288
    TextDirection? textDirection,
289
    VerticalDirection verticalDirection = VerticalDirection.down,
290
    TextBaseline? textBaseline,
291
    Clip clipBehavior = Clip.none,
292 293 294 295
  }) : assert(direction != null),
       assert(mainAxisAlignment != null),
       assert(mainAxisSize != null),
       assert(crossAxisAlignment != null),
296
       assert(clipBehavior != null),
297
       _direction = direction,
298
       _mainAxisAlignment = mainAxisAlignment,
299
       _mainAxisSize = mainAxisSize,
300
       _crossAxisAlignment = crossAxisAlignment,
301 302
       _textDirection = textDirection,
       _verticalDirection = verticalDirection,
303 304
       _textBaseline = textBaseline,
       _clipBehavior = clipBehavior {
305 306 307
    addAll(children);
  }

308
  /// The direction to use as the main axis.
309 310
  Axis get direction => _direction;
  Axis _direction;
311
  set direction(Axis value) {
312
    assert(value != null);
313 314 315 316 317 318
    if (_direction != value) {
      _direction = value;
      markNeedsLayout();
    }
  }

319
  /// How the children should be placed along the main axis.
320 321 322 323 324 325 326 327
  ///
  /// If the [direction] is [Axis.horizontal], and the [mainAxisAlignment] is
  /// either [MainAxisAlignment.start] or [MainAxisAlignment.end], then the
  /// [textDirection] must not be null.
  ///
  /// If the [direction] is [Axis.vertical], and the [mainAxisAlignment] is
  /// either [MainAxisAlignment.start] or [MainAxisAlignment.end], then the
  /// [verticalDirection] must not be null.
328 329
  MainAxisAlignment get mainAxisAlignment => _mainAxisAlignment;
  MainAxisAlignment _mainAxisAlignment;
330
  set mainAxisAlignment(MainAxisAlignment value) {
331
    assert(value != null);
332 333
    if (_mainAxisAlignment != value) {
      _mainAxisAlignment = value;
334 335 336 337
      markNeedsLayout();
    }
  }

338
  /// How much space should be occupied in the main axis.
339 340 341
  ///
  /// After allocating space to children, there might be some remaining free
  /// space. This value controls whether to maximize or minimize the amount of
342
  /// free space, subject to the incoming layout constraints.
343 344 345 346 347
  ///
  /// If some children have a non-zero flex factors (and none have a fit of
  /// [FlexFit.loose]), they will expand to consume all the available space and
  /// there will be no remaining free space to maximize or minimize, making this
  /// value irrelevant to the final layout.
348 349
  MainAxisSize get mainAxisSize => _mainAxisSize;
  MainAxisSize _mainAxisSize;
350
  set mainAxisSize(MainAxisSize value) {
351
    assert(value != null);
352 353 354 355 356 357
    if (_mainAxisSize != value) {
      _mainAxisSize = value;
      markNeedsLayout();
    }
  }

358
  /// How the children should be placed along the cross axis.
359 360 361 362 363 364 365 366
  ///
  /// If the [direction] is [Axis.horizontal], and the [crossAxisAlignment] is
  /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the
  /// [verticalDirection] must not be null.
  ///
  /// If the [direction] is [Axis.vertical], and the [crossAxisAlignment] is
  /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the
  /// [textDirection] must not be null.
367 368
  CrossAxisAlignment get crossAxisAlignment => _crossAxisAlignment;
  CrossAxisAlignment _crossAxisAlignment;
369
  set crossAxisAlignment(CrossAxisAlignment value) {
370
    assert(value != null);
371 372
    if (_crossAxisAlignment != value) {
      _crossAxisAlignment = value;
373 374 375 376
      markNeedsLayout();
    }
  }

377 378 379
  /// Determines the order to lay children out horizontally and how to interpret
  /// `start` and `end` in the horizontal direction.
  ///
380 381
  /// If the [direction] is [Axis.horizontal], this controls the order in which
  /// children are positioned (left-to-right or right-to-left), and the meaning
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
  /// of the [mainAxisAlignment] property's [MainAxisAlignment.start] and
  /// [MainAxisAlignment.end] values.
  ///
  /// If the [direction] is [Axis.horizontal], and either the
  /// [mainAxisAlignment] is either [MainAxisAlignment.start] or
  /// [MainAxisAlignment.end], or there's more than one child, then the
  /// [textDirection] must not be null.
  ///
  /// If the [direction] is [Axis.vertical], this controls the meaning of the
  /// [crossAxisAlignment] property's [CrossAxisAlignment.start] and
  /// [CrossAxisAlignment.end] values.
  ///
  /// If the [direction] is [Axis.vertical], and the [crossAxisAlignment] is
  /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the
  /// [textDirection] must not be null.
397 398 399
  TextDirection? get textDirection => _textDirection;
  TextDirection? _textDirection;
  set textDirection(TextDirection? value) {
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    if (_textDirection != value) {
      _textDirection = value;
      markNeedsLayout();
    }
  }

  /// Determines the order to lay children out vertically and how to interpret
  /// `start` and `end` in the vertical direction.
  ///
  /// If the [direction] is [Axis.vertical], this controls which order children
  /// are painted in (down or up), the meaning of the [mainAxisAlignment]
  /// property's [MainAxisAlignment.start] and [MainAxisAlignment.end] values.
  ///
  /// If the [direction] is [Axis.vertical], and either the [mainAxisAlignment]
  /// is either [MainAxisAlignment.start] or [MainAxisAlignment.end], or there's
  /// more than one child, then the [verticalDirection] must not be null.
  ///
  /// If the [direction] is [Axis.horizontal], this controls the meaning of the
  /// [crossAxisAlignment] property's [CrossAxisAlignment.start] and
  /// [CrossAxisAlignment.end] values.
  ///
  /// If the [direction] is [Axis.horizontal], and the [crossAxisAlignment] is
  /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the
  /// [verticalDirection] must not be null.
  VerticalDirection get verticalDirection => _verticalDirection;
  VerticalDirection _verticalDirection;
  set verticalDirection(VerticalDirection value) {
    if (_verticalDirection != value) {
      _verticalDirection = value;
      markNeedsLayout();
    }
  }

433
  /// If aligning items according to their baseline, which baseline to use.
434 435
  ///
  /// Must not be null if [crossAxisAlignment] is [CrossAxisAlignment.baseline].
436 437 438
  TextBaseline? get textBaseline => _textBaseline;
  TextBaseline? _textBaseline;
  set textBaseline(TextBaseline? value) {
439
    assert(_crossAxisAlignment != CrossAxisAlignment.baseline || value != null);
440 441 442 443 444 445
    if (_textBaseline != value) {
      _textBaseline = value;
      markNeedsLayout();
    }
  }

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
  bool get _debugHasNecessaryDirections {
    assert(direction != null);
    assert(crossAxisAlignment != null);
    if (firstChild != null && lastChild != firstChild) {
      // i.e. there's more than one child
      switch (direction) {
        case Axis.horizontal:
          assert(textDirection != null, 'Horizontal $runtimeType with multiple children has a null textDirection, so the layout order is undefined.');
          break;
        case Axis.vertical:
          assert(verticalDirection != null, 'Vertical $runtimeType with multiple children has a null verticalDirection, so the layout order is undefined.');
          break;
      }
    }
    if (mainAxisAlignment == MainAxisAlignment.start ||
        mainAxisAlignment == MainAxisAlignment.end) {
      switch (direction) {
        case Axis.horizontal:
          assert(textDirection != null, 'Horizontal $runtimeType with $mainAxisAlignment has a null textDirection, so the alignment cannot be resolved.');
          break;
        case Axis.vertical:
          assert(verticalDirection != null, 'Vertical $runtimeType with $mainAxisAlignment has a null verticalDirection, so the alignment cannot be resolved.');
          break;
      }
470 471
    }
    if (crossAxisAlignment == CrossAxisAlignment.start ||
472 473 474 475 476 477 478 479 480 481 482 483 484
        crossAxisAlignment == CrossAxisAlignment.end) {
      switch (direction) {
        case Axis.horizontal:
          assert(verticalDirection != null, 'Horizontal $runtimeType with $crossAxisAlignment has a null verticalDirection, so the alignment cannot be resolved.');
          break;
        case Axis.vertical:
          assert(textDirection != null, 'Vertical $runtimeType with $crossAxisAlignment has a null textDirection, so the alignment cannot be resolved.');
          break;
      }
    }
    return true;
  }

485
  // Set during layout if overflow occurred on the main axis.
486
  double _overflow = 0;
487 488
  // Check whether any meaningful overflow is present. Values below an epsilon
  // are treated as not overflowing.
489
  bool get _hasOverflow => _overflow > precisionErrorTolerance;
490

491
  /// {@macro flutter.material.Material.clipBehavior}
492 493 494 495 496 497 498 499 500 501 502 503 504
  ///
  /// Defaults to [Clip.none], and must not be null.
  Clip get clipBehavior => _clipBehavior;
  Clip _clipBehavior = Clip.none;
  set clipBehavior(Clip value) {
    assert(value != null);
    if (value != _clipBehavior) {
      _clipBehavior = value;
      markNeedsPaint();
      markNeedsSemanticsUpdate();
    }
  }

505
  @override
506
  void setupParentData(RenderBox child) {
507
    if (child.parentData is! FlexParentData)
508
      child.parentData = FlexParentData();
509 510
  }

511 512
  bool get _canComputeIntrinsics => crossAxisAlignment != CrossAxisAlignment.baseline;

513
  double _getIntrinsicSize({
514 515 516
    required Axis sizingDirection,
    required double extent, // the extent in the direction that isn't the sizing direction
    required _ChildSizingFunction childSize, // a method to find the size in the sizing direction
517
  }) {
518
    if (!_canComputeIntrinsics) {
519 520 521 522 523
      // Intrinsics cannot be calculated without a full layout for
      // baseline alignment. Throw an assertion and return 0.0 as documented
      // on [RenderBox.computeMinIntrinsicWidth].
      assert(
        RenderObject.debugCheckingIntrinsics,
524
        'Intrinsics are not available for CrossAxisAlignment.baseline.',
525 526 527
      );
      return 0.0;
    }
528 529 530 531 532 533 534
    if (_direction == sizingDirection) {
      // INTRINSIC MAIN SIZE
      // Intrinsic main size is the smallest size the flex container can take
      // while maintaining the min/max-content contributions of its flex items.
      double totalFlex = 0.0;
      double inflexibleSpace = 0.0;
      double maxFlexFractionSoFar = 0.0;
535
      RenderBox? child = firstChild;
536
      while (child != null) {
537
        final int flex = _getFlex(child);
538 539
        totalFlex += flex;
        if (flex > 0) {
540
          final double flexFraction = childSize(child, extent) / _getFlex(child);
541 542
          maxFlexFractionSoFar = math.max(maxFlexFractionSoFar, flexFraction);
        } else {
543
          inflexibleSpace += childSize(child, extent);
544
        }
545
        final FlexParentData childParentData = child.parentData! as FlexParentData;
Hixie's avatar
Hixie committed
546
        child = childParentData.nextSibling;
547
      }
548
      return maxFlexFractionSoFar * totalFlex + inflexibleSpace;
549 550
    } else {
      // INTRINSIC CROSS SIZE
551 552 553
      // Intrinsic cross size is the max of the intrinsic cross sizes of the
      // children, after the flexible children are fit into the available space,
      // with the children sized using their max intrinsic dimensions.
554

555
      // Get inflexible space using the max intrinsic dimensions of fixed children in the main direction.
556
      final double availableMainSpace = extent;
557 558 559
      int totalFlex = 0;
      double inflexibleSpace = 0.0;
      double maxCrossSize = 0.0;
560
      RenderBox? child = firstChild;
561
      while (child != null) {
562
        final int flex = _getFlex(child);
563
        totalFlex += flex;
564 565
        late final double mainSize;
        late final double crossSize;
566 567
        if (flex == 0) {
          switch (_direction) {
568 569 570 571 572 573 574 575
            case Axis.horizontal:
              mainSize = child.getMaxIntrinsicWidth(double.infinity);
              crossSize = childSize(child, mainSize);
              break;
            case Axis.vertical:
              mainSize = child.getMaxIntrinsicHeight(double.infinity);
              crossSize = childSize(child, mainSize);
              break;
576 577 578 579
          }
          inflexibleSpace += mainSize;
          maxCrossSize = math.max(maxCrossSize, crossSize);
        }
580
        final FlexParentData childParentData = child.parentData! as FlexParentData;
Hixie's avatar
Hixie committed
581
        child = childParentData.nextSibling;
582 583
      }

584
      // Determine the spacePerFlex by allocating the remaining available space.
585
      // When you're overconstrained spacePerFlex can be negative.
586
      final double spacePerFlex = math.max(0.0, (availableMainSpace - inflexibleSpace) / totalFlex);
587

588
      // Size remaining (flexible) items, find the maximum cross size.
589 590
      child = firstChild;
      while (child != null) {
591
        final int flex = _getFlex(child);
592 593
        if (flex > 0)
          maxCrossSize = math.max(maxCrossSize, childSize(child, spacePerFlex * flex));
594
        final FlexParentData childParentData = child.parentData! as FlexParentData;
Hixie's avatar
Hixie committed
595
        child = childParentData.nextSibling;
596 597
      }

598
      return maxCrossSize;
599 600 601
    }
  }

602
  @override
603
  double computeMinIntrinsicWidth(double height) {
604
    return _getIntrinsicSize(
605
      sizingDirection: Axis.horizontal,
606
      extent: height,
607
      childSize: (RenderBox child, double extent) => child.getMinIntrinsicWidth(extent),
608 609 610
    );
  }

611
  @override
612
  double computeMaxIntrinsicWidth(double height) {
613
    return _getIntrinsicSize(
614
      sizingDirection: Axis.horizontal,
615
      extent: height,
616
      childSize: (RenderBox child, double extent) => child.getMaxIntrinsicWidth(extent),
617 618 619
    );
  }

620
  @override
621
  double computeMinIntrinsicHeight(double width) {
622
    return _getIntrinsicSize(
623
      sizingDirection: Axis.vertical,
624
      extent: width,
625
      childSize: (RenderBox child, double extent) => child.getMinIntrinsicHeight(extent),
626 627 628
    );
  }

629
  @override
630
  double computeMaxIntrinsicHeight(double width) {
631
    return _getIntrinsicSize(
632
      sizingDirection: Axis.vertical,
633
      extent: width,
634
      childSize: (RenderBox child, double extent) => child.getMaxIntrinsicHeight(extent),
635
    );
636 637
  }

638
  @override
639
  double? computeDistanceToActualBaseline(TextBaseline baseline) {
640
    if (_direction == Axis.horizontal)
641 642 643 644 645
      return defaultComputeDistanceToHighestActualBaseline(baseline);
    return defaultComputeDistanceToFirstActualBaseline(baseline);
  }

  int _getFlex(RenderBox child) {
646
    final FlexParentData childParentData = child.parentData! as FlexParentData;
Adam Barth's avatar
Adam Barth committed
647 648 649 650
    return childParentData.flex ?? 0;
  }

  FlexFit _getFit(RenderBox child) {
651
    final FlexParentData childParentData = child.parentData! as FlexParentData;
Adam Barth's avatar
Adam Barth committed
652
    return childParentData.fit ?? FlexFit.tight;
653 654
  }

655
  double _getCrossSize(Size size) {
656 657
    switch (_direction) {
      case Axis.horizontal:
658
        return size.height;
659
      case Axis.vertical:
660
        return size.width;
661
    }
662 663
  }

664
  double _getMainSize(Size size) {
665 666
    switch (_direction) {
      case Axis.horizontal:
667
        return size.width;
668
      case Axis.vertical:
669
        return size.height;
670
    }
671 672
  }

673
  @override
674 675 676
  Size computeDryLayout(BoxConstraints constraints) {
    if (!_canComputeIntrinsics) {
      assert(debugCannotComputeDryLayout(
677
        reason: 'Dry layout cannot be computed for CrossAxisAlignment.baseline, which requires a full layout.',
678
      ));
679
      return Size.zero;
680 681 682 683 684 685 686 687 688 689 690
    }
    FlutterError? constraintsError;
    assert(() {
      constraintsError = _debugCheckConstraints(
        constraints: constraints,
        reportParentConstraints: false,
      );
      return true;
    }());
    if (constraintsError != null) {
      assert(debugCannotComputeDryLayout(error: constraintsError));
691
      return Size.zero;
692
    }
693

694 695 696 697
    final _LayoutSizes sizes = _computeSizes(
      layoutChild: ChildLayoutHelper.dryLayoutChild,
      constraints: constraints,
    );
698

699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
    switch (_direction) {
      case Axis.horizontal:
        return constraints.constrain(Size(sizes.mainSize, sizes.crossSize));
      case Axis.vertical:
        return constraints.constrain(Size(sizes.crossSize, sizes.mainSize));
    }
  }

  FlutterError? _debugCheckConstraints({required BoxConstraints constraints, required bool reportParentConstraints}) {
    FlutterError? result;
    assert(() {
      final double maxMainSize = _direction == Axis.horizontal ? constraints.maxWidth : constraints.maxHeight;
      final bool canFlex = maxMainSize < double.infinity;
      RenderBox? child = firstChild;
      while (child != null) {
        final int flex = _getFlex(child);
        if (flex > 0) {
716 717 718
          final String identity = _direction == Axis.horizontal ? 'row' : 'column';
          final String axis = _direction == Axis.horizontal ? 'horizontal' : 'vertical';
          final String dimension = _direction == Axis.horizontal ? 'width' : 'height';
719 720
          DiagnosticsNode error, message;
          final List<DiagnosticsNode> addendum = <DiagnosticsNode>[];
721
          if (!canFlex && (mainAxisSize == MainAxisSize.max || _getFit(child) == FlexFit.tight)) {
722 723 724 725 726
            error = ErrorSummary('RenderFlex children have non-zero flex but incoming $dimension constraints are unbounded.');
            message = ErrorDescription(
              'When a $identity is in a parent that does not provide a finite $dimension constraint, for example '
              'if it is in a $axis scrollable, it will try to shrink-wrap its children along the $axis '
              'axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to '
727
              'expand to fill the remaining space in the $axis direction.',
728
            );
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
            if (reportParentConstraints) { // Constraints of parents are unavailable in dry layout.
              RenderBox? node = this;
              switch (_direction) {
                case Axis.horizontal:
                  while (!node!.constraints.hasBoundedWidth && node.parent is RenderBox)
                    node = node.parent! as RenderBox;
                  if (!node.constraints.hasBoundedWidth)
                    node = null;
                  break;
                case Axis.vertical:
                  while (!node!.constraints.hasBoundedHeight && node.parent is RenderBox)
                    node = node.parent! as RenderBox;
                  if (!node.constraints.hasBoundedHeight)
                    node = null;
                  break;
              }
              if (node != null) {
                addendum.add(node.describeForError('The nearest ancestor providing an unbounded width constraint is'));
              }
748
            }
749
            addendum.add(ErrorHint('See also: https://flutter.dev/layout/'));
750 751 752
          } else {
            return true;
          }
753
          result = FlutterError.fromParts(<DiagnosticsNode>[
754 755 756 757
            error,
            message,
            ErrorDescription(
              'These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child '
758
              'cannot simultaneously expand to fit its parent.',
759 760 761 762 763 764
            ),
            ErrorHint(
              'Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible '
              'children (using Flexible rather than Expanded). This will allow the flexible children '
              'to size themselves to less than the infinite remaining space they would otherwise be '
              'forced to take, and then will cause the RenderFlex to shrink-wrap the children '
765
              'rather than expanding to fit the maximum constraints provided by the parent.',
766 767 768 769
            ),
            ErrorDescription(
              'If this message did not help you determine the problem, consider using debugDumpRenderTree():\n'
              '  https://flutter.dev/debugging/#rendering-layer\n'
770
              '  http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html',
771 772
            ),
            describeForError('The affected RenderFlex is', style: DiagnosticsTreeStyle.errorProperty),
773 774 775
            DiagnosticsProperty<dynamic>('The creator information is set to', debugCreator, style: DiagnosticsTreeStyle.errorProperty),
            ...addendum,
            ErrorDescription(
776
              "If none of the above helps enough to fix this problem, please don't hesitate to file a bug:\n"
777
              '  https://github.com/flutter/flutter/issues/new?template=2_bug.md',
778
            ),
779
          ]);
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
          return true;
        }
        child = childAfter(child);
      }
      return true;
    }());
    return result;
  }

  _LayoutSizes _computeSizes({required BoxConstraints constraints, required ChildLayouter layoutChild}) {
    assert(_debugHasNecessaryDirections);
    assert(constraints != null);

    // Determine used flex factor, size inflexible items, calculate free space.
    int totalFlex = 0;
    final double maxMainSize = _direction == Axis.horizontal ? constraints.maxWidth : constraints.maxHeight;
    final bool canFlex = maxMainSize < double.infinity;

    double crossSize = 0.0;
    double allocatedSize = 0.0; // Sum of the sizes of the non-flexible children.
    RenderBox? child = firstChild;
    RenderBox? lastFlexChild;
    while (child != null) {
      final FlexParentData childParentData = child.parentData! as FlexParentData;
      final int flex = _getFlex(child);
      if (flex > 0) {
806
        totalFlex += flex;
807
        lastFlexChild = child;
808
      } else {
809
        final BoxConstraints innerConstraints;
810
        if (crossAxisAlignment == CrossAxisAlignment.stretch) {
811
          switch (_direction) {
812
            case Axis.horizontal:
813
              innerConstraints = BoxConstraints.tightFor(height: constraints.maxHeight);
814
              break;
815
            case Axis.vertical:
816
              innerConstraints = BoxConstraints.tightFor(width: constraints.maxWidth);
817 818 819
              break;
          }
        } else {
820
          switch (_direction) {
821
            case Axis.horizontal:
822
              innerConstraints = BoxConstraints(maxHeight: constraints.maxHeight);
823
              break;
824
            case Axis.vertical:
825
              innerConstraints = BoxConstraints(maxWidth: constraints.maxWidth);
826 827
              break;
          }
828
        }
829 830 831
        final Size childSize = layoutChild(child, innerConstraints);
        allocatedSize += _getMainSize(childSize);
        crossSize = math.max(crossSize, _getCrossSize(childSize));
832
      }
Hixie's avatar
Hixie committed
833 834
      assert(child.parentData == childParentData);
      child = childParentData.nextSibling;
835 836
    }

837
    // Distribute free space to flexible children.
838
    final double freeSpace = math.max(0.0, (canFlex ? maxMainSize : 0.0) - allocatedSize);
839
    double allocatedFlexSpace = 0.0;
840 841
    if (totalFlex > 0) {
      final double spacePerFlex = canFlex ? (freeSpace / totalFlex) : double.nan;
842 843
      child = firstChild;
      while (child != null) {
Adam Barth's avatar
Adam Barth committed
844
        final int flex = _getFlex(child);
845
        if (flex > 0) {
846
          final double maxChildExtent = canFlex ? (child == lastFlexChild ? (freeSpace - allocatedFlexSpace) : spacePerFlex * flex) : double.infinity;
847
          late final double minChildExtent;
Adam Barth's avatar
Adam Barth committed
848 849
          switch (_getFit(child)) {
            case FlexFit.tight:
850
              assert(maxChildExtent < double.infinity);
Adam Barth's avatar
Adam Barth committed
851 852 853 854 855 856 857
              minChildExtent = maxChildExtent;
              break;
            case FlexFit.loose:
              minChildExtent = 0.0;
              break;
          }
          assert(minChildExtent != null);
858
          final BoxConstraints innerConstraints;
859
          if (crossAxisAlignment == CrossAxisAlignment.stretch) {
860
            switch (_direction) {
861
              case Axis.horizontal:
862 863 864 865 866 867
                innerConstraints = BoxConstraints(
                  minWidth: minChildExtent,
                  maxWidth: maxChildExtent,
                  minHeight: constraints.maxHeight,
                  maxHeight: constraints.maxHeight,
                );
868
                break;
869
              case Axis.vertical:
870 871 872 873 874 875
                innerConstraints = BoxConstraints(
                  minWidth: constraints.maxWidth,
                  maxWidth: constraints.maxWidth,
                  minHeight: minChildExtent,
                  maxHeight: maxChildExtent,
                );
876 877 878 879
                break;
            }
          } else {
            switch (_direction) {
880
              case Axis.horizontal:
881 882 883 884 885
                innerConstraints = BoxConstraints(
                  minWidth: minChildExtent,
                  maxWidth: maxChildExtent,
                  maxHeight: constraints.maxHeight,
                );
886
                break;
887
              case Axis.vertical:
888 889 890 891 892
                innerConstraints = BoxConstraints(
                  maxWidth: constraints.maxWidth,
                  minHeight: minChildExtent,
                  maxHeight: maxChildExtent,
                );
893 894
                break;
            }
895
          }
896 897 898 899
          final Size childSize = layoutChild(child, innerConstraints);
          final double childMainSize = _getMainSize(childSize);
          assert(childMainSize <= maxChildExtent);
          allocatedSize += childMainSize;
900
          allocatedFlexSpace += maxChildExtent;
901
          crossSize = math.max(crossSize, _getCrossSize(childSize));
902
        }
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
        final FlexParentData childParentData = child.parentData! as FlexParentData;
        child = childParentData.nextSibling;
      }
    }

    final double idealSize = canFlex && mainAxisSize == MainAxisSize.max ? maxMainSize : allocatedSize;
    return _LayoutSizes(
      mainSize: idealSize,
      crossSize: crossSize,
      allocatedSize: allocatedSize,
    );
  }

  @override
  void performLayout() {
    assert(_debugHasNecessaryDirections);
    final BoxConstraints constraints = this.constraints;
    assert(() {
      final FlutterError? constraintsError = _debugCheckConstraints(
        constraints: constraints,
        reportParentConstraints: true,
      );
      if (constraintsError != null) {
        throw constraintsError;
      }
      return true;
    }());

    final _LayoutSizes sizes = _computeSizes(
      layoutChild: ChildLayoutHelper.layoutChild,
      constraints: constraints,
    );

    final double allocatedSize = sizes.allocatedSize;
    double actualSize = sizes.mainSize;
    double crossSize = sizes.crossSize;
    double maxBaselineDistance = 0.0;
    if (crossAxisAlignment == CrossAxisAlignment.baseline) {
      RenderBox? child = firstChild;
      double maxSizeAboveBaseline = 0;
      double maxSizeBelowBaseline = 0;
      while (child != null) {
        assert(() {
          if (textBaseline == null)
            throw FlutterError('To use FlexAlignItems.baseline, you must also specify which baseline to use using the "baseline" argument.');
          return true;
        }());
        final double? distance = child.getDistanceToBaseline(textBaseline!, onlyReal: true);
        if (distance != null) {
          maxBaselineDistance = math.max(maxBaselineDistance, distance);
          maxSizeAboveBaseline = math.max(
            distance,
            maxSizeAboveBaseline,
          );
          maxSizeBelowBaseline = math.max(
            child.size.height - distance,
            maxSizeBelowBaseline,
          );
          crossSize = math.max(maxSizeAboveBaseline + maxSizeBelowBaseline, crossSize);
962
        }
963
        final FlexParentData childParentData = child.parentData! as FlexParentData;
Hixie's avatar
Hixie committed
964
        child = childParentData.nextSibling;
965
      }
966 967
    }

968
    // Align items along the main axis.
969 970
    switch (_direction) {
      case Axis.horizontal:
971
        size = constraints.constrain(Size(actualSize, crossSize));
972 973 974 975
        actualSize = size.width;
        crossSize = size.height;
        break;
      case Axis.vertical:
976
        size = constraints.constrain(Size(crossSize, actualSize));
977 978 979
        actualSize = size.height;
        crossSize = size.width;
        break;
980
    }
981
    final double actualSizeDelta = actualSize - allocatedSize;
982 983
    _overflow = math.max(0.0, -actualSizeDelta);
    final double remainingSpace = math.max(0.0, actualSizeDelta);
984 985
    late final double leadingSpace;
    late final double betweenSpace;
986 987 988 989 990
    // flipMainAxis is used to decide whether to lay out left-to-right/top-to-bottom (false), or
    // right-to-left/bottom-to-top (true). The _startIsTopLeft will return null if there's only
    // one child and the relevant direction is null, in which case we arbitrarily decide not to
    // flip, but that doesn't have any detectable effect.
    final bool flipMainAxis = !(_startIsTopLeft(direction, textDirection, verticalDirection) ?? true);
991 992
    switch (_mainAxisAlignment) {
      case MainAxisAlignment.start:
993 994 995
        leadingSpace = 0.0;
        betweenSpace = 0.0;
        break;
996
      case MainAxisAlignment.end:
997 998 999
        leadingSpace = remainingSpace;
        betweenSpace = 0.0;
        break;
1000
      case MainAxisAlignment.center:
1001 1002 1003
        leadingSpace = remainingSpace / 2.0;
        betweenSpace = 0.0;
        break;
1004
      case MainAxisAlignment.spaceBetween:
1005
        leadingSpace = 0.0;
1006
        betweenSpace = childCount > 1 ? remainingSpace / (childCount - 1) : 0.0;
1007
        break;
1008
      case MainAxisAlignment.spaceAround:
1009
        betweenSpace = childCount > 0 ? remainingSpace / childCount : 0.0;
1010 1011
        leadingSpace = betweenSpace / 2.0;
        break;
1012
      case MainAxisAlignment.spaceEvenly:
1013
        betweenSpace = childCount > 0 ? remainingSpace / (childCount + 1) : 0.0;
1014 1015
        leadingSpace = betweenSpace;
        break;
1016 1017
    }

Collin Jackson's avatar
Collin Jackson committed
1018
    // Position elements
1019
    double childMainPosition = flipMainAxis ? actualSize - leadingSpace : leadingSpace;
1020
    RenderBox? child = firstChild;
1021
    while (child != null) {
1022
      final FlexParentData childParentData = child.parentData! as FlexParentData;
1023
      final double childCrossPosition;
1024 1025 1026
      switch (_crossAxisAlignment) {
        case CrossAxisAlignment.start:
        case CrossAxisAlignment.end:
1027 1028 1029
          childCrossPosition = _startIsTopLeft(flipAxis(direction), textDirection, verticalDirection)
                               == (_crossAxisAlignment == CrossAxisAlignment.start)
                             ? 0.0
1030
                             : crossSize - _getCrossSize(child.size);
1031
          break;
1032
        case CrossAxisAlignment.center:
1033
          childCrossPosition = crossSize / 2.0 - _getCrossSize(child.size) / 2.0;
1034
          break;
1035 1036 1037
        case CrossAxisAlignment.stretch:
          childCrossPosition = 0.0;
          break;
1038
        case CrossAxisAlignment.baseline:
1039
          if (_direction == Axis.horizontal) {
1040
            assert(textBaseline != null);
1041
            final double? distance = child.getDistanceToBaseline(textBaseline!, onlyReal: true);
1042 1043
            if (distance != null)
              childCrossPosition = maxBaselineDistance - distance;
1044 1045 1046 1047
            else
              childCrossPosition = 0.0;
          } else {
            childCrossPosition = 0.0;
1048 1049
          }
          break;
1050
      }
1051
      if (flipMainAxis)
1052
        childMainPosition -= _getMainSize(child.size);
1053
      switch (_direction) {
1054
        case Axis.horizontal:
1055
          childParentData.offset = Offset(childMainPosition, childCrossPosition);
1056
          break;
1057
        case Axis.vertical:
1058
          childParentData.offset = Offset(childCrossPosition, childMainPosition);
1059 1060
          break;
      }
1061 1062 1063
      if (flipMainAxis) {
        childMainPosition -= betweenSpace;
      } else {
1064
        childMainPosition += _getMainSize(child.size) + betweenSpace;
1065
      }
Hixie's avatar
Hixie committed
1066
      child = childParentData.nextSibling;
1067 1068 1069
    }
  }

1070
  @override
1071
  bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
Adam Barth's avatar
Adam Barth committed
1072
    return defaultHitTestChildren(result, position: position);
1073 1074
  }

1075
  @override
1076
  void paint(PaintingContext context, Offset offset) {
1077
    if (!_hasOverflow) {
1078
      defaultPaint(context, offset);
1079
      return;
1080
    }
Collin Jackson's avatar
Collin Jackson committed
1081

1082 1083 1084 1085
    // There's no point in drawing the children if we're empty.
    if (size.isEmpty)
      return;

1086
    if (clipBehavior == Clip.none) {
1087
      _clipRectLayer.layer = null;
1088 1089 1090
      defaultPaint(context, offset);
    } else {
      // We have overflow and the clipBehavior isn't none. Clip it.
1091
      _clipRectLayer.layer = context.pushClipRect(
1092 1093 1094 1095 1096
        needsCompositing,
        offset,
        Offset.zero & size,
        defaultPaint,
        clipBehavior: clipBehavior,
1097
        oldLayer: _clipRectLayer.layer,
1098
      );
1099
    }
1100

1101
    assert(() {
1102
      // Only set this if it's null to save work. It gets reset to null if the
1103
      // _direction changes.
1104 1105
      final List<DiagnosticsNode> debugOverflowHints = <DiagnosticsNode>[
        ErrorDescription(
1106
          'The overflowing $runtimeType has an orientation of $_direction.',
1107 1108 1109 1110
        ),
        ErrorDescription(
          'The edge of the $runtimeType that is overflowing has been marked '
          'in the rendering with a yellow and black striped pattern. This is '
1111
          'usually caused by the contents being too big for the $runtimeType.',
1112 1113 1114 1115
        ),
        ErrorHint(
          'Consider applying a flex factor (e.g. using an Expanded widget) to '
          'force the children of the $runtimeType to fit within the available '
1116
          'space instead of being sized to their natural size.',
1117 1118 1119 1120 1121 1122
        ),
        ErrorHint(
          'This is considered an error condition because it indicates that there '
          'is content that cannot be seen. If the content is legitimately bigger '
          'than the available space, consider clipping it with a ClipRect widget '
          'before putting it in the flex, or using a scrollable container rather '
1123
          'than a Flex, like a ListView.',
1124
        ),
1125
      ];
1126 1127 1128 1129

      // Simulate a child rect that overflows by the right amount. This child
      // rect is never used for drawing, just for determining the overflow
      // location and amount.
1130
      final Rect overflowChildRect;
1131
      switch (_direction) {
1132
        case Axis.horizontal:
1133
          overflowChildRect = Rect.fromLTWH(0.0, 0.0, size.width + _overflow, 0.0);
1134
          break;
1135
        case Axis.vertical:
1136
          overflowChildRect = Rect.fromLTWH(0.0, 0.0, 0.0, size.height + _overflow);
1137 1138
          break;
      }
1139
      paintOverflowIndicator(context, offset, Offset.zero & size, overflowChildRect, overflowHints: debugOverflowHints);
1140
      return true;
1141
    }());
1142
  }
Collin Jackson's avatar
Collin Jackson committed
1143

1144 1145 1146 1147 1148 1149 1150
  final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>();

  @override
  void dispose() {
    _clipRectLayer.layer = null;
    super.dispose();
  }
1151

1152
  @override
1153
  Rect? describeApproximatePaintClip(RenderObject child) => _hasOverflow ? Offset.zero & size : null;
Hixie's avatar
Hixie committed
1154

1155
  @override
1156 1157
  String toStringShort() {
    String header = super.toStringShort();
1158
    if (_hasOverflow)
1159 1160
      header += ' OVERFLOWING';
    return header;
Collin Jackson's avatar
Collin Jackson committed
1161
  }
1162

1163
  @override
1164 1165
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
1166 1167 1168 1169 1170 1171 1172
    properties.add(EnumProperty<Axis>('direction', direction));
    properties.add(EnumProperty<MainAxisAlignment>('mainAxisAlignment', mainAxisAlignment));
    properties.add(EnumProperty<MainAxisSize>('mainAxisSize', mainAxisSize));
    properties.add(EnumProperty<CrossAxisAlignment>('crossAxisAlignment', crossAxisAlignment));
    properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null));
    properties.add(EnumProperty<VerticalDirection>('verticalDirection', verticalDirection, defaultValue: null));
    properties.add(EnumProperty<TextBaseline>('textBaseline', textBaseline, defaultValue: null));
1173
  }
1174
}
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186

class _LayoutSizes {
  const _LayoutSizes({
    required this.mainSize,
    required this.crossSize,
    required this.allocatedSize,
  });

  final double mainSize;
  final double crossSize;
  final double allocatedSize;
}