row_test.dart 41.6 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/foundation.dart';
6 7
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import 'package:flutter_test/flutter_test.dart';

class OrderPainter extends CustomPainter {
  const OrderPainter(this.index);

  final int index;

  static List<int> log = <int>[];

  @override
  void paint(Canvas canvas, Size size) {
    log.add(index);
  }

  @override
  bool shouldRepaint(OrderPainter old) => false;
}

26
Widget log(int index) => CustomPaint(painter: OrderPainter(index));
27 28

void main() {
29 30 31 32
  // NO DIRECTION

  testWidgets('Row with one Flexible child - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
33 34 35 36
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
37 38 39 40 41 42 43 44

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // Default is MainAxisAlignment.start so this should fail, asking for a direction.
45 46
    await tester.pumpWidget(Center(
      child: Row(
47 48
        key: rowKey,
        children: <Widget>[
49 50 51
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Expanded(child: Container(key: child1Key, width: 100.0, height: 100.0, child: log(2))),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
52 53 54 55 56 57 58 59 60 61 62 63
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row with default main axis parameters - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
64 65 66 67
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
68 69 70 71 72 73 74 75

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // Default is MainAxisAlignment.start so this should fail too.
76 77
    await tester.pumpWidget(Center(
      child: Row(
78 79
        key: rowKey,
        children: <Widget>[
80 81 82
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
83 84 85 86 87 88 89 90 91 92 93 94
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row with MainAxisAlignment.center - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
95 96 97
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
98 99 100 101 102 103 104 105

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // More than one child, so it's not clear what direction to lay out in: should fail.
106 107
    await tester.pumpWidget(Center(
      child: Row(
108 109 110
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
111 112
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
113 114 115 116 117 118 119 120 121 122 123 124
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row with MainAxisAlignment.end - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
125 126 127 128
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
129 130 131 132 133 134 135 136

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // No direction so this should fail, asking for a direction.
137 138
    await tester.pumpWidget(Center(
      child: Row(
139 140 141
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
142 143 144
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
145 146 147 148 149 150 151 152 153 154 155 156
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row with MainAxisAlignment.spaceBetween - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
157 158 159 160
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
161 162 163 164 165 166 167 168

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // More than one child, so it's not clear what direction to lay out in: should fail.
169 170
    await tester.pumpWidget(Center(
      child: Row(
171 172 173
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
174 175 176
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
177 178 179 180 181 182 183 184 185 186 187 188
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row with MainAxisAlignment.spaceAround - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
189 190 191 192 193
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
    const Key child3Key = Key('child3');
194 195 196 197 198 199 200 201

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // More than one child, so it's not clear what direction to lay out in: should fail.
202 203
    await tester.pumpWidget(Center(
      child: Row(
204 205 206
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
207 208 209 210
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
          Container(key: child3Key, width: 100.0, height: 100.0, child: log(4)),
211 212 213 214 215 216 217 218 219 220 221 222
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row with MainAxisAlignment.spaceEvenly - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
223 224 225 226
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
227 228 229 230 231 232 233 234

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // More than one child, so it's not clear what direction to lay out in: should fail.
235 236
    await tester.pumpWidget(Center(
      child: Row(
237 238 239
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
240 241 242
          Container(key: child0Key, width: 200.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 200.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 200.0, height: 100.0, child: log(3)),
243 244 245 246 247 248 249 250 251 252 253 254
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row and MainAxisSize.min - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
255 256 257
    const Key rowKey = Key('rowKey');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
258 259 260 261 262 263 264 265

    final FlutterExceptionHandler oldHandler = FlutterError.onError;
    dynamic exception;
    FlutterError.onError = (FlutterErrorDetails details) {
      exception ??= details.exception;
    };

    // Default is MainAxisAlignment.start so this should fail, asking for a direction.
266 267
    await tester.pumpWidget(Center(
      child: Row(
268 269 270
        key: rowKey,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
271 272
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 150.0, height: 100.0, child: log(2)),
273 274 275 276 277 278 279 280 281 282 283 284
        ],
      ),
    ));

    FlutterError.onError = oldHandler;
    expect(exception, isAssertionError);
    expect(exception.toString(), contains('textDirection'));
    expect(OrderPainter.log, <int>[]);
  });

  testWidgets('Row MainAxisSize.min layout at zero size - no textDirection', (WidgetTester tester) async {
    OrderPainter.log.clear();
285
    const Key childKey = Key('childKey');
286

287 288
    await tester.pumpWidget(Center(
      child: Container(
289 290
        width: 0.0,
        height: 0.0,
291
        child: Row(
292 293 294
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
295
            Container(
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
              key: childKey,
              width: 100.0,
              height: 100.0,
            ),
          ],
        ),
      ),
    ));

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


  // LTR

  testWidgets('Row with one Flexible child - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
315 316 317 318
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
319 320 321 322

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // Default is MainAxisAlignment.start so children so the children's
    // left edges should be at 0, 100, 700, child2's width should be 600
323 324
    await tester.pumpWidget(Center(
      child: Row(
325
        key: rowKey,
326
        textDirection: TextDirection.ltr,
327
        children: <Widget>[
328 329 330
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Expanded(child: Container(key: child1Key, width: 100.0, height: 100.0, child: log(2))),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
331 332
        ],
      ),
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(600.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(700.0));
359 360

    expect(OrderPainter.log, <int>[1, 2, 3]);
361 362
  });

363 364
  testWidgets('Row with default main axis parameters - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
365 366 367 368
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
369 370 371 372

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // Default is MainAxisAlignment.start so children so the children's
    // left edges should be at 0, 100, 200
373 374
    await tester.pumpWidget(Center(
      child: Row(
375
        key: rowKey,
376
        textDirection: TextDirection.ltr,
377
        children: <Widget>[
378 379 380
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
381 382
        ],
      ),
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(200.0));
409 410

    expect(OrderPainter.log, <int>[1, 2, 3]);
411 412
  });

413 414
  testWidgets('Row with MainAxisAlignment.center - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
415 416 417
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
418 419 420

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's left edges should be at 300, 400
421 422
    await tester.pumpWidget(Center(
      child: Row(
423 424
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.center,
425
        textDirection: TextDirection.ltr,
426
        children: <Widget>[
427 428
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
429 430
        ],
      ),
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(300.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(400.0));
451 452

    expect(OrderPainter.log, <int>[1, 2]);
453 454
  });

455 456
  testWidgets('Row with MainAxisAlignment.end - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
457 458 459 460
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
461 462 463

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's left edges should be at 500, 600, 700.
464 465
    await tester.pumpWidget(Center(
      child: Row(
466
        key: rowKey,
467
        textDirection: TextDirection.ltr,
468 469
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
470 471 472
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
473 474
        ],
      ),
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(500.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(700.0));
501 502

    expect(OrderPainter.log, <int>[1, 2, 3]);
503 504
  });

505 506
  testWidgets('Row with MainAxisAlignment.spaceBetween - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
507 508 509 510
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
511 512 513

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's left edges should be at 0, 350, 700
514 515
    await tester.pumpWidget(Center(
      child: Row(
516 517
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
518
        textDirection: TextDirection.ltr,
519
        children: <Widget>[
520 521 522
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
523 524
        ],
      ),
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(350.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(700.0));
551 552

    expect(OrderPainter.log, <int>[1, 2, 3]);
553 554
  });

555 556
  testWidgets('Row with MainAxisAlignment.spaceAround - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
557 558 559 560 561
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
    const Key child3Key = Key('child3');
562 563 564

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's left edges should be at 50, 250, 450, 650
565 566
    await tester.pumpWidget(Center(
      child: Row(
567 568
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
569
        textDirection: TextDirection.ltr,
570
        children: <Widget>[
571 572 573 574
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
          Container(key: child3Key, width: 100.0, height: 100.0, child: log(4)),
575 576
        ],
      ),
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(50.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(250.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(450.0));

    renderBox = tester.renderObject(find.byKey(child3Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(650.0));
609 610

    expect(OrderPainter.log, <int>[1, 2, 3, 4]);
611 612
  });

613 614
  testWidgets('Row with MainAxisAlignment.spaceEvenly - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
615 616 617 618
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
619 620 621

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 200x100 children's left edges should be at 50, 300, 550
622 623
    await tester.pumpWidget(Center(
      child: Row(
624 625
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
626
        textDirection: TextDirection.ltr,
627
        children: <Widget>[
628 629 630
          Container(key: child0Key, width: 200.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 200.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 200.0, height: 100.0, child: log(3)),
631 632
        ],
      ),
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(200.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(50.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(200.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(300.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(200.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(550.0));
659 660

    expect(OrderPainter.log, <int>[1, 2, 3]);
661 662
  });

663 664
  testWidgets('Row and MainAxisSize.min - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
665 666 667
    const Key rowKey = Key('rowKey');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
668 669 670

    // Row with MainAxisSize.min without flexible children shrink wraps.
    // Row's width should be 250, children should be at 0, 100.
671 672
    await tester.pumpWidget(Center(
      child: Row(
673 674
        key: rowKey,
        mainAxisSize: MainAxisSize.min,
675
        textDirection: TextDirection.ltr,
676
        children: <Widget>[
677 678
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 150.0, height: 100.0, child: log(2)),
679 680
        ],
      ),
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(150.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(100.0));
701 702 703 704 705 706

    expect(OrderPainter.log, <int>[1, 2]);
  });

  testWidgets('Row MainAxisSize.min layout at zero size - LTR', (WidgetTester tester) async {
    OrderPainter.log.clear();
707
    const Key childKey = Key('childKey');
708

709 710
    await tester.pumpWidget(Center(
      child: Container(
711 712
        width: 0.0,
        height: 0.0,
713
        child: Row(
714 715 716 717
          textDirection: TextDirection.ltr,
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
718
            Container(
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
              key: childKey,
              width: 100.0,
              height: 100.0,
            ),
          ],
        ),
      ),
    ));

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


  // RTL

  testWidgets('Row with one Flexible child - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
738 739 740 741
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
742 743 744 745

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // Default is MainAxisAlignment.start so children so the children's
    // right edges should be at 0, 100, 700 from the right, child2's width should be 600
746 747
    await tester.pumpWidget(Center(
      child: Row(
748 749 750
        key: rowKey,
        textDirection: TextDirection.rtl,
        children: <Widget>[
751 752 753
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Expanded(child: Container(key: child1Key, width: 100.0, height: 100.0, child: log(2))),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(700.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(600.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    expect(OrderPainter.log, <int>[1, 2, 3]);
  });

  testWidgets('Row with default main axis parameters - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
788 789 790 791
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
792 793 794 795

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // Default is MainAxisAlignment.start so children so the children's
    // right edges should be at 0, 100, 200 from the right
796 797
    await tester.pumpWidget(Center(
      child: Row(
798 799 800
        key: rowKey,
        textDirection: TextDirection.rtl,
        children: <Widget>[
801 802 803
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(700.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(600.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(500.0));

    expect(OrderPainter.log, <int>[1, 2, 3]);
  });

  testWidgets('Row with MainAxisAlignment.center - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
838 839 840
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
841 842 843

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's right edges should be at 300, 400 from the right
844 845
    await tester.pumpWidget(Center(
      child: Row(
846 847 848 849
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.center,
        textDirection: TextDirection.rtl,
        children: <Widget>[
850 851
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(400.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(300.0));

    expect(OrderPainter.log, <int>[1, 2]);
  });

  testWidgets('Row with MainAxisAlignment.end - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
880 881 882 883
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
884 885 886

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's right edges should be at 500, 600, 700 from the right.
887 888
    await tester.pumpWidget(Center(
      child: Row(
889 890 891 892
        key: rowKey,
        textDirection: TextDirection.rtl,
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
893 894 895
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
896 897 898 899 900 901 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
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(200.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(100.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    expect(OrderPainter.log, <int>[1, 2, 3]);
  });

  testWidgets('Row with MainAxisAlignment.spaceBetween - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
930 931 932 933
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
934 935 936

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's right edges should be at 0, 350, 700 from the right
937 938
    await tester.pumpWidget(Center(
      child: Row(
939 940 941 942
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        textDirection: TextDirection.rtl,
        children: <Widget>[
943 944 945
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(700.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(350.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    expect(OrderPainter.log, <int>[1, 2, 3]);
  });

  testWidgets('Row with MainAxisAlignment.spaceAround - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
980 981 982 983 984
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
    const Key child3Key = Key('child3');
985 986 987

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 100x100 children's right edges should be at 50, 250, 450, 650 from the right
988 989
    await tester.pumpWidget(Center(
      child: Row(
990 991 992 993
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        textDirection: TextDirection.rtl,
        children: <Widget>[
994 995 996 997
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 100.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 100.0, height: 100.0, child: log(3)),
          Container(key: child3Key, width: 100.0, height: 100.0, child: log(4)),
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(650.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(450.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(250.0));

    renderBox = tester.renderObject(find.byKey(child3Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(50.0));

    expect(OrderPainter.log, <int>[1, 2, 3, 4]);
  });

  testWidgets('Row with MainAxisAlignment.spaceEvenly - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
1038 1039 1040 1041
    const Key rowKey = Key('row');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
    const Key child2Key = Key('child2');
1042 1043 1044

    // Default is MainAxisSize.max so the Row should be as wide as the test: 800.
    // The 200x100 children's right edges should be at 50, 300, 550 from the right
1045 1046
    await tester.pumpWidget(Center(
      child: Row(
1047 1048 1049 1050
        key: rowKey,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        textDirection: TextDirection.rtl,
        children: <Widget>[
1051 1052 1053
          Container(key: child0Key, width: 200.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 200.0, height: 100.0, child: log(2)),
          Container(key: child2Key, width: 200.0, height: 100.0, child: log(3)),
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(200.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(550.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(200.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(300.0));

    renderBox = tester.renderObject(find.byKey(child2Key));
    expect(renderBox.size.width, equals(200.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(50.0));

    expect(OrderPainter.log, <int>[1, 2, 3]);
  });

  testWidgets('Row and MainAxisSize.min - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
1088 1089 1090
    const Key rowKey = Key('rowKey');
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
1091 1092 1093

    // Row with MainAxisSize.min without flexible children shrink wraps.
    // Row's width should be 250, children should be at 0, 100 from right.
1094 1095
    await tester.pumpWidget(Center(
      child: Row(
1096 1097 1098 1099
        key: rowKey,
        mainAxisSize: MainAxisSize.min,
        textDirection: TextDirection.rtl,
        children: <Widget>[
1100 1101
          Container(key: child0Key, width: 100.0, height: 100.0, child: log(1)),
          Container(key: child1Key, width: 150.0, height: 100.0, child: log(2)),
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
        ],
      ),
    ));

    RenderBox renderBox;
    BoxParentData boxParentData;

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

    renderBox = tester.renderObject(find.byKey(child0Key));
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(150.0));

    renderBox = tester.renderObject(find.byKey(child1Key));
    expect(renderBox.size.width, equals(150.0));
    expect(renderBox.size.height, equals(100.0));
    boxParentData = renderBox.parentData;
    expect(boxParentData.offset.dx, equals(0.0));

    expect(OrderPainter.log, <int>[1, 2]);
1126 1127
  });

1128 1129
  testWidgets('Row MainAxisSize.min layout at zero size - RTL', (WidgetTester tester) async {
    OrderPainter.log.clear();
1130
    const Key childKey = Key('childKey');
1131

1132 1133
    await tester.pumpWidget(Center(
      child: Container(
1134 1135
        width: 0.0,
        height: 0.0,
1136
        child: Row(
1137 1138 1139
          textDirection: TextDirection.rtl,
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
1140
          children: <Widget>[
1141
            Container(
1142 1143
              key: childKey,
              width: 100.0,
1144 1145
              height: 100.0,
            ),
1146
          ],
1147 1148
        ),
      ),
1149 1150
    ));

1151
    final RenderBox renderBox = tester.renderObject(find.byKey(childKey));
1152 1153 1154 1155
    expect(renderBox.size.width, equals(100.0));
    expect(renderBox.size.height, equals(0.0));
  });
}