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

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

void main() {
10 11
  // DOWN (default)

12
  testWidgets('Column with one flexible child', (WidgetTester tester) async {
13 14 15 16
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
17 18 19 20

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // Default is MainAxisAlignment.start so children so the children's
    // top edges should be at 0, 100, 500, child2's height should be 400.
21 22
    await tester.pumpWidget(Center(
      child: Column(
23 24
        key: columnKey,
        children: <Widget>[
25 26 27
          Container(key: child0Key, width: 100.0, height: 100.0),
          Expanded(child: Container(key: child1Key, width: 100.0, height: 100.0)),
          Container(key: child2Key, width: 100.0, height: 100.0),
28 29
        ],
      ),
30 31 32 33 34 35 36 37 38 39 40 41
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
42
    boxParentData = renderBox.parentData as BoxParentData;
43 44 45 46 47
    expect(boxParentData.offset.dy, equals(0.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(400.0));
48
    boxParentData = renderBox.parentData as BoxParentData;
49 50 51 52 53
    expect(boxParentData.offset.dy, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
54
    boxParentData = renderBox.parentData as BoxParentData;
55 56 57 58
    expect(boxParentData.offset.dy, equals(500.0));
  });

  testWidgets('Column with default main axis parameters', (WidgetTester tester) async {
59 60 61 62
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
63 64 65 66

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // Default is MainAxisAlignment.start so children so the children's
    // top edges should be at 0, 100, 200
67 68
    await tester.pumpWidget(Center(
      child: Column(
69 70
        key: columnKey,
        children: <Widget>[
71 72 73
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
74 75
        ],
      ),
76 77 78 79 80 81 82 83 84 85 86 87
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
88
    boxParentData = renderBox.parentData as BoxParentData;
89 90 91 92 93
    expect(boxParentData.offset.dy, equals(0.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
94
    boxParentData = renderBox.parentData as BoxParentData;
95 96 97 98 99
    expect(boxParentData.offset.dy, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
100
    boxParentData = renderBox.parentData as BoxParentData;
101 102 103 104
    expect(boxParentData.offset.dy, equals(200.0));
  });

  testWidgets('Column with MainAxisAlignment.center', (WidgetTester tester) async {
105 106 107
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
108 109 110

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's top edges should be at 200, 300
111 112
    await tester.pumpWidget(Center(
      child: Column(
113 114 115
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
116 117
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
118 119
        ],
      ),
120 121 122 123 124 125 126 127 128 129 130 131
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
132
    boxParentData = renderBox.parentData as BoxParentData;
133 134 135 136 137
    expect(boxParentData.offset.dy, equals(200.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
138
    boxParentData = renderBox.parentData as BoxParentData;
139 140 141 142
    expect(boxParentData.offset.dy, equals(300.0));
  });

  testWidgets('Column with MainAxisAlignment.end', (WidgetTester tester) async {
143 144 145 146
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
147 148 149

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's top edges should be at 300, 400, 500.
150 151
    await tester.pumpWidget(Center(
      child: Column(
152 153 154
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
155 156 157
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
158 159
        ],
      ),
160 161 162 163 164 165 166 167 168 169 170 171
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
172
    boxParentData = renderBox.parentData as BoxParentData;
173 174 175 176 177
    expect(boxParentData.offset.dy, equals(300.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
178
    boxParentData = renderBox.parentData as BoxParentData;
179 180 181 182 183
    expect(boxParentData.offset.dy, equals(400.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
184
    boxParentData = renderBox.parentData as BoxParentData;
185 186 187 188
    expect(boxParentData.offset.dy, equals(500.0));
  });

  testWidgets('Column with MainAxisAlignment.spaceBetween', (WidgetTester tester) async {
189 190 191 192
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
193 194 195

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's top edges should be at 0, 250, 500
196 197
    await tester.pumpWidget(Center(
      child: Column(
198 199 200
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
201 202 203
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
204 205
        ],
      ),
206 207 208 209 210 211 212 213 214 215 216 217
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
218
    boxParentData = renderBox.parentData as BoxParentData;
219 220 221 222 223
    expect(boxParentData.offset.dy, equals(0.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
224
    boxParentData = renderBox.parentData as BoxParentData;
225 226 227 228 229
    expect(boxParentData.offset.dy, equals(250.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
230
    boxParentData = renderBox.parentData as BoxParentData;
231 232 233 234
    expect(boxParentData.offset.dy, equals(500.0));
  });

  testWidgets('Column with MainAxisAlignment.spaceAround', (WidgetTester tester) async {
235 236 237 238 239
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
    const Key child3Key = Key('child3');
240 241 242

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's top edges should be at 25, 175, 325, 475
243 244
    await tester.pumpWidget(Center(
      child: Column(
245 246 247
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
248 249 250 251
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
          Container(key: child3Key, width: 100.0, height: 100.0),
252 253
        ],
      ),
254 255 256 257 258 259 260 261 262 263 264 265
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
266
    boxParentData = renderBox.parentData as BoxParentData;
267 268 269 270 271
    expect(boxParentData.offset.dy, equals(25.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
272
    boxParentData = renderBox.parentData as BoxParentData;
273 274 275 276 277
    expect(boxParentData.offset.dy, equals(175.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
278
    boxParentData = renderBox.parentData as BoxParentData;
279 280 281 282 283
    expect(boxParentData.offset.dy, equals(325.0));

    renderBox = tester.renderObject(find.byKey(child3Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
284
    boxParentData = renderBox.parentData as BoxParentData;
285 286 287 288
    expect(boxParentData.offset.dy, equals(475.0));
  });

  testWidgets('Column with MainAxisAlignment.spaceEvenly', (WidgetTester tester) async {
289 290 291 292
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
293 294 295

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x20 children's top edges should be at 135, 290, 445
296 297
    await tester.pumpWidget(Center(
      child: Column(
298 299 300
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
301 302 303
          Container(key: child0Key, width: 100.0, height: 20.0),
          Container(key: child1Key, width: 100.0, height: 20.0),
          Container(key: child2Key, width: 100.0, height: 20.0),
304 305
        ],
      ),
306 307 308 309 310 311 312 313 314 315 316 317
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(20.0));
318
    boxParentData = renderBox.parentData as BoxParentData;
319 320 321 322 323
    expect(boxParentData.offset.dy, equals(135.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(20.0));
324
    boxParentData = renderBox.parentData as BoxParentData;
325 326 327 328 329
    expect(boxParentData.offset.dy, equals(290.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(20.0));
330
    boxParentData = renderBox.parentData as BoxParentData;
331 332 333 334
    expect(boxParentData.offset.dy, equals(445.0));
  });

  testWidgets('Column and MainAxisSize.min', (WidgetTester tester) async {
335
    const Key flexKey = Key('flexKey');
336 337

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
338 339
    await tester.pumpWidget(Center(
      child: Column(
340 341
        key: flexKey,
        children: <Widget>[
342
          Container(width: 100.0, height: 100.0),
343 344 345
          Container(width: 100.0, height: 150.0),
        ],
      ),
346 347 348 349 350 351
    ));
    RenderBox renderBox = tester.renderObject(find.byKey(flexKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    // Column with MainAxisSize.min without flexible children shrink wraps.
352 353
    await tester.pumpWidget(Center(
      child: Column(
354 355 356
        key: flexKey,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
357
          Container(width: 100.0, height: 100.0),
358 359 360
          Container(width: 100.0, height: 150.0),
        ],
      ),
361 362 363 364 365 366 367
    ));
    renderBox = tester.renderObject(find.byKey(flexKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(250.0));
  });

  testWidgets('Column MainAxisSize.min layout at zero size', (WidgetTester tester) async {
368
    const Key childKey = Key('childKey');
369

370 371
    await tester.pumpWidget(Center(
      child: Container(
372 373
        width: 0.0,
        height: 0.0,
374
        child: Column(
375 376
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
377
            Container(
378 379
              key: childKey,
              width: 100.0,
380 381 382 383 384
              height: 100.0,
            ),
          ],
        ),
      ),
385 386
    ));

387
    final RenderBox renderBox = tester.renderObject(find.byKey(childKey));
388 389 390
    expect(renderBox.size.width, equals(0.0));
    expect(renderBox.size.height, equals(100.0));
  });
391 392 393 394 395


  // UP

  testWidgets('Column with one flexible child', (WidgetTester tester) async {
396 397 398 399
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
400 401 402 403

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // Default is MainAxisAlignment.start so children so the children's
    // bottom edges should be at 0, 100, 500 from bottom, child2's height should be 400.
404 405
    await tester.pumpWidget(Center(
      child: Column(
406 407 408
        key: columnKey,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
409 410 411
          Container(key: child0Key, width: 100.0, height: 100.0),
          Expanded(child: Container(key: child1Key, width: 100.0, height: 100.0)),
          Container(key: child2Key, width: 100.0, height: 100.0),
412 413
        ],
      ),
414 415 416 417 418 419 420 421 422 423 424 425
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
426
    boxParentData = renderBox.parentData as BoxParentData;
427 428 429 430 431
    expect(boxParentData.offset.dy, equals(500.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(400.0));
432
    boxParentData = renderBox.parentData as BoxParentData;
433 434 435 436 437
    expect(boxParentData.offset.dy, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
438
    boxParentData = renderBox.parentData as BoxParentData;
439 440 441 442
    expect(boxParentData.offset.dy, equals(0.0));
  });

  testWidgets('Column with default main axis parameters', (WidgetTester tester) async {
443 444 445 446
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
447 448 449 450

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // Default is MainAxisAlignment.start so children so the children's
    // bottom edges should be at 0, 100, 200 from bottom
451 452
    await tester.pumpWidget(Center(
      child: Column(
453 454 455
        key: columnKey,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
456 457 458
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
459 460
        ],
      ),
461 462 463 464 465 466 467 468 469 470 471 472
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
473
    boxParentData = renderBox.parentData as BoxParentData;
474 475 476 477 478
    expect(boxParentData.offset.dy, equals(500.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
479
    boxParentData = renderBox.parentData as BoxParentData;
480 481 482 483 484
    expect(boxParentData.offset.dy, equals(400.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
485
    boxParentData = renderBox.parentData as BoxParentData;
486 487 488 489
    expect(boxParentData.offset.dy, equals(300.0));
  });

  testWidgets('Column with MainAxisAlignment.center', (WidgetTester tester) async {
490 491 492
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
493 494 495

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's bottom edges should be at 200, 300 from bottom
496 497
    await tester.pumpWidget(Center(
      child: Column(
498 499 500 501
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.center,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
502 503
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
504 505
        ],
      ),
506 507 508 509 510 511 512 513 514 515 516 517
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
518
    boxParentData = renderBox.parentData as BoxParentData;
519 520 521 522 523
    expect(boxParentData.offset.dy, equals(300.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
524
    boxParentData = renderBox.parentData as BoxParentData;
525 526 527 528
    expect(boxParentData.offset.dy, equals(200.0));
  });

  testWidgets('Column with MainAxisAlignment.end', (WidgetTester tester) async {
529 530 531 532
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
533 534 535

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's bottom edges should be at 300, 400, 500 from bottom.
536 537
    await tester.pumpWidget(Center(
      child: Column(
538 539 540 541
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.end,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
542 543 544
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
545 546
        ],
      ),
547 548 549 550 551 552 553 554 555 556 557 558
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
559
    boxParentData = renderBox.parentData as BoxParentData;
560 561 562 563 564
    expect(boxParentData.offset.dy, equals(200.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
565
    boxParentData = renderBox.parentData as BoxParentData;
566 567 568 569 570
    expect(boxParentData.offset.dy, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
571
    boxParentData = renderBox.parentData as BoxParentData;
572 573 574 575
    expect(boxParentData.offset.dy, equals(0.0));
  });

  testWidgets('Column with MainAxisAlignment.spaceBetween', (WidgetTester tester) async {
576 577 578 579
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
580 581 582

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's bottom edges should be at 0, 250, 500 from bottom
583 584
    await tester.pumpWidget(Center(
      child: Column(
585 586 587 588
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
589 590 591
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
592 593
        ],
      ),
594 595 596 597 598 599 600 601 602 603 604 605
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
606
    boxParentData = renderBox.parentData as BoxParentData;
607 608 609 610 611
    expect(boxParentData.offset.dy, equals(500.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
612
    boxParentData = renderBox.parentData as BoxParentData;
613 614 615 616 617
    expect(boxParentData.offset.dy, equals(250.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
618
    boxParentData = renderBox.parentData as BoxParentData;
619 620 621 622
    expect(boxParentData.offset.dy, equals(0.0));
  });

  testWidgets('Column with MainAxisAlignment.spaceAround', (WidgetTester tester) async {
623 624 625 626 627
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
    const Key child3Key = Key('child3');
628 629 630

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x100 children's bottom edges should be at 25, 175, 325, 475 from bottom
631 632
    await tester.pumpWidget(Center(
      child: Column(
633 634 635 636
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
637 638 639 640
          Container(key: child0Key, width: 100.0, height: 100.0),
          Container(key: child1Key, width: 100.0, height: 100.0),
          Container(key: child2Key, width: 100.0, height: 100.0),
          Container(key: child3Key, width: 100.0, height: 100.0),
641 642
        ],
      ),
643 644 645 646 647 648 649 650 651 652 653 654
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
655
    boxParentData = renderBox.parentData as BoxParentData;
656 657 658 659 660
    expect(boxParentData.offset.dy, equals(500.0 - 25.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
661
    boxParentData = renderBox.parentData as BoxParentData;
662 663 664 665 666
    expect(boxParentData.offset.dy, equals(500.0 - 175.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
667
    boxParentData = renderBox.parentData as BoxParentData;
668 669 670 671 672
    expect(boxParentData.offset.dy, equals(500.0 - 325.0));

    renderBox = tester.renderObject(find.byKey(child3Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
673
    boxParentData = renderBox.parentData as BoxParentData;
674 675 676 677
    expect(boxParentData.offset.dy, equals(500.0 - 475.0));
  });

  testWidgets('Column with MainAxisAlignment.spaceEvenly', (WidgetTester tester) async {
678 679 680 681
    const Key columnKey = Key('column');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
682 683 684

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
    // The 100x20 children's bottom edges should be at 135, 290, 445 from bottom
685 686
    await tester.pumpWidget(Center(
      child: Column(
687 688 689 690
        key: columnKey,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
691 692 693
          Container(key: child0Key, width: 100.0, height: 20.0),
          Container(key: child1Key, width: 100.0, height: 20.0),
          Container(key: child2Key, width: 100.0, height: 20.0),
694 695
        ],
      ),
696 697 698 699 700 701 702 703 704 705 706 707
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

    renderBox = tester.renderObject(find.byKey(columnKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(20.0));
708
    boxParentData = renderBox.parentData as BoxParentData;
709 710 711 712 713
    expect(boxParentData.offset.dy, equals(600.0 - 135.0 - 20.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(20.0));
714
    boxParentData = renderBox.parentData as BoxParentData;
715 716 717 718 719
    expect(boxParentData.offset.dy, equals(600.0 - 290.0 - 20.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(20.0));
720
    boxParentData = renderBox.parentData as BoxParentData;
721 722 723 724
    expect(boxParentData.offset.dy, equals(600.0 - 445.0 - 20.0));
  });

  testWidgets('Column and MainAxisSize.min', (WidgetTester tester) async {
725
    const Key flexKey = Key('flexKey');
726 727

    // Default is MainAxisSize.max so the Column should be as high as the test: 600.
728 729
    await tester.pumpWidget(Center(
      child: Column(
730 731 732
        key: flexKey,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
733
          Container(width: 100.0, height: 100.0),
734 735 736
          Container(width: 100.0, height: 150.0),
        ],
      ),
737 738 739 740 741 742
    ));
    RenderBox renderBox = tester.renderObject(find.byKey(flexKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(600.0));

    // Column with MainAxisSize.min without flexible children shrink wraps.
743 744
    await tester.pumpWidget(Center(
      child: Column(
745 746 747 748
        key: flexKey,
        mainAxisSize: MainAxisSize.min,
        verticalDirection: VerticalDirection.up,
        children: <Widget>[
749
          Container(width: 100.0, height: 100.0),
750 751 752
          Container(width: 100.0, height: 150.0),
        ],
      ),
753 754 755 756 757 758 759
    ));
    renderBox = tester.renderObject(find.byKey(flexKey));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(250.0));
  });

  testWidgets('Column MainAxisSize.min layout at zero size', (WidgetTester tester) async {
760
    const Key childKey = Key('childKey');
761

762 763
    await tester.pumpWidget(Center(
      child: Container(
764 765
        width: 0.0,
        height: 0.0,
766
        child: Column(
767 768 769
          mainAxisSize: MainAxisSize.min,
          verticalDirection: VerticalDirection.up,
          children: <Widget>[
770
            Container(
771 772
              key: childKey,
              width: 100.0,
773 774 775 776 777
              height: 100.0,
            ),
          ],
        ),
      ),
778 779 780 781 782 783
    ));

    final RenderBox renderBox = tester.renderObject(find.byKey(childKey));
    expect(renderBox.size.width, equals(0.0));
    expect(renderBox.size.height, equals(100.0));
  });
784
}