stack_test.dart 25.8 KB
Newer Older
Hixie's avatar
Hixie committed
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.

Adam Barth's avatar
Adam Barth committed
5
import 'package:flutter_test/flutter_test.dart';
6
import 'package:flutter/rendering.dart';
7
import 'package:flutter/widgets.dart';
8

9
import '../rendering/rendering_tester.dart';
10

11 12 13 14
class TestPaintingContext implements PaintingContext {
  final List<Invocation> invocations = <Invocation>[];

  @override
15 16 17
  void noSuchMethod(Invocation invocation) {
    invocations.add(invocation);
  }
18 19
}

20
void main() {
21
  testWidgets('Can construct an empty Stack', (WidgetTester tester) async {
22
    await tester.pumpWidget(
23
      Directionality(
24
        textDirection: TextDirection.ltr,
25
        child: Stack(),
26 27
      ),
    );
Hans Muller's avatar
Hans Muller committed
28 29
  });

30
  testWidgets('Can construct an empty Centered Stack', (WidgetTester tester) async {
31
    await tester.pumpWidget(
32
      Directionality(
33
        textDirection: TextDirection.ltr,
34
        child: Center(child: Stack()),
35 36
      ),
    );
37 38
  });

39
  testWidgets('Can change position data', (WidgetTester tester) async {
40
    const Key key = Key('container');
41

42
    await tester.pumpWidget(
43
      Stack(
44
        alignment: Alignment.topLeft,
45
        children: <Widget>[
46
          Positioned(
47
            left: 10.0,
48
            child: Container(
49 50
              key: key,
              width: 10.0,
51 52 53 54 55
              height: 10.0,
            ),
          ),
        ],
      ),
56 57 58 59 60 61 62 63 64 65 66 67 68 69
    );

    Element container;
    StackParentData parentData;

    container = tester.element(find.byKey(key));
    parentData = container.renderObject.parentData;
    expect(parentData.top, isNull);
    expect(parentData.right, isNull);
    expect(parentData.bottom, isNull);
    expect(parentData.left, equals(10.0));
    expect(parentData.width, isNull);
    expect(parentData.height, isNull);

70
    await tester.pumpWidget(
71
      Stack(
72
        alignment: Alignment.topLeft,
73
        children: <Widget>[
74
          Positioned(
75
            right: 10.0,
76
            child: Container(
77 78
              key: key,
              width: 10.0,
79 80 81 82 83
              height: 10.0,
            ),
          ),
        ],
      ),
84 85 86 87 88 89 90 91 92 93
    );

    container = tester.element(find.byKey(key));
    parentData = container.renderObject.parentData;
    expect(parentData.top, isNull);
    expect(parentData.right, equals(10.0));
    expect(parentData.bottom, isNull);
    expect(parentData.left, isNull);
    expect(parentData.width, isNull);
    expect(parentData.height, isNull);
94
  });
95

96
  testWidgets('Can remove parent data', (WidgetTester tester) async {
97
    const Key key = Key('container');
98
    final Container container = Container(key: key, width: 10.0, height: 10.0);
99

100
    await tester.pumpWidget(
101
      Stack(
102
        textDirection: TextDirection.ltr,
103
        children: <Widget>[ Positioned(left: 10.0, child: container) ],
104 105
      ),
    );
106 107 108 109 110 111 112 113 114 115 116
    Element containerElement = tester.element(find.byKey(key));

    StackParentData parentData;
    parentData = containerElement.renderObject.parentData;
    expect(parentData.top, isNull);
    expect(parentData.right, isNull);
    expect(parentData.bottom, isNull);
    expect(parentData.left, equals(10.0));
    expect(parentData.width, isNull);
    expect(parentData.height, isNull);

117
    await tester.pumpWidget(
118
      Stack(
119 120 121 122
        textDirection: TextDirection.ltr,
        children: <Widget>[ container ],
      ),
    );
123 124 125 126 127 128 129 130 131
    containerElement = tester.element(find.byKey(key));

    parentData = containerElement.renderObject.parentData;
    expect(parentData.top, isNull);
    expect(parentData.right, isNull);
    expect(parentData.bottom, isNull);
    expect(parentData.left, isNull);
    expect(parentData.width, isNull);
    expect(parentData.height, isNull);
132
  });
Hans Muller's avatar
Hans Muller committed
133

134
  testWidgets('Can align non-positioned children (LTR)', (WidgetTester tester) async {
135 136
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
137

138
    await tester.pumpWidget(
139
      Directionality(
140
        textDirection: TextDirection.ltr,
141 142
        child: Center(
          child: Stack(
143
            alignment: Alignment.center,
144
            children: <Widget>[
145 146
              Container(key: child0Key, width: 20.0, height: 20.0),
              Container(key: child1Key, width: 10.0, height: 10.0),
147 148 149 150
            ],
          ),
        ),
      ),
151
    );
Hans Muller's avatar
Hans Muller committed
152

153
    final Element child0 = tester.element(find.byKey(child0Key));
154 155
    final StackParentData child0RenderObjectParentData = child0.renderObject.parentData;
    expect(child0RenderObjectParentData.offset, equals(const Offset(0.0, 0.0)));
Hans Muller's avatar
Hans Muller committed
156

157
    final Element child1 = tester.element(find.byKey(child1Key));
158 159
    final StackParentData child1RenderObjectParentData = child1.renderObject.parentData;
    expect(child1RenderObjectParentData.offset, equals(const Offset(5.0, 5.0)));
160 161

    await tester.pumpWidget(
162
      Directionality(
163
        textDirection: TextDirection.ltr,
164 165
        child: Center(
          child: Stack(
166
            alignment: AlignmentDirectional.bottomEnd,
167
            children: <Widget>[
168 169
              Container(key: child0Key, width: 20.0, height: 20.0),
              Container(key: child1Key, width: 10.0, height: 10.0),
170 171 172 173 174 175 176 177 178 179 180
            ],
          ),
        ),
      ),
    );

    expect(child0RenderObjectParentData.offset, equals(const Offset(0.0, 0.0)));
    expect(child1RenderObjectParentData.offset, equals(const Offset(10.0, 10.0)));
  });

  testWidgets('Can align non-positioned children (RTL)', (WidgetTester tester) async {
181 182
    const Key child0Key = Key('child0');
    const Key child1Key = Key('child1');
183 184

    await tester.pumpWidget(
185
      Directionality(
186
        textDirection: TextDirection.rtl,
187 188
        child: Center(
          child: Stack(
189
            alignment: Alignment.center,
190
            children: <Widget>[
191 192
              Container(key: child0Key, width: 20.0, height: 20.0),
              Container(key: child1Key, width: 10.0, height: 10.0),
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
            ],
          ),
        ),
      ),
    );

    final Element child0 = tester.element(find.byKey(child0Key));
    final StackParentData child0RenderObjectParentData = child0.renderObject.parentData;
    expect(child0RenderObjectParentData.offset, equals(const Offset(0.0, 0.0)));

    final Element child1 = tester.element(find.byKey(child1Key));
    final StackParentData child1RenderObjectParentData = child1.renderObject.parentData;
    expect(child1RenderObjectParentData.offset, equals(const Offset(5.0, 5.0)));

    await tester.pumpWidget(
208
      Directionality(
209
        textDirection: TextDirection.rtl,
210 211
        child: Center(
          child: Stack(
212
            alignment: AlignmentDirectional.bottomEnd,
213
            children: <Widget>[
214 215
              Container(key: child0Key, width: 20.0, height: 20.0),
              Container(key: child1Key, width: 10.0, height: 10.0),
216 217 218 219 220 221 222 223
            ],
          ),
        ),
      ),
    );

    expect(child0RenderObjectParentData.offset, equals(const Offset(0.0, 0.0)));
    expect(child1RenderObjectParentData.offset, equals(const Offset(0.0, 10.0)));
Hans Muller's avatar
Hans Muller committed
224 225
  });

226
  testWidgets('Can construct an empty IndexedStack', (WidgetTester tester) async {
227
    await tester.pumpWidget(
228
      Directionality(
229
        textDirection: TextDirection.ltr,
230
        child: IndexedStack(),
231 232
      ),
    );
Hans Muller's avatar
Hans Muller committed
233 234
  });

235
  testWidgets('Can construct an empty Centered IndexedStack', (WidgetTester tester) async {
236
    await tester.pumpWidget(
237
      Directionality(
238
        textDirection: TextDirection.ltr,
239
        child: Center(child: IndexedStack()),
240 241
      ),
    );
242 243
  });

244
  testWidgets('Can construct an IndexedStack', (WidgetTester tester) async {
245
    const int itemCount = 3;
246 247 248 249
    List<int> itemsPainted;

    Widget buildFrame(int index) {
      itemsPainted = <int>[];
250 251 252 253
      final List<Widget> items = List<Widget>.generate(itemCount, (int i) {
        return CustomPaint(
          child: Text('$i', textDirection: TextDirection.ltr),
          painter: TestCallbackPainter(
254
            onPaint: () { itemsPainted.add(i); }
255
          ),
256 257
        );
      });
258 259
      return Center(
        child: IndexedStack(
260
          alignment: Alignment.topLeft,
261 262 263 264
          children: items,
          index: index,
        ),
      );
265 266
    }

267
    await tester.pumpWidget(buildFrame(0));
268 269 270
    expect(find.text('0'), findsOneWidget);
    expect(find.text('1'), findsOneWidget);
    expect(find.text('2'), findsOneWidget);
271
    expect(itemsPainted, equals(<int>[0]));
272

273
    await tester.pumpWidget(buildFrame(1));
274
    expect(itemsPainted, equals(<int>[1]));
275

276
    await tester.pumpWidget(buildFrame(2));
277
    expect(itemsPainted, equals(<int>[2]));
Hans Muller's avatar
Hans Muller committed
278 279
  });

280
  testWidgets('Can hit test an IndexedStack', (WidgetTester tester) async {
281
    const Key key = Key('indexedStack');
282
    const int itemCount = 3;
283 284 285 286
    List<int> itemsTapped;

    Widget buildFrame(int index) {
      itemsTapped = <int>[];
287 288
      final List<Widget> items = List<Widget>.generate(itemCount, (int i) {
        return GestureDetector(child: Text('$i', textDirection: TextDirection.ltr), onTap: () { itemsTapped.add(i); });
289
      });
290 291
      return Center(
        child: IndexedStack(
292
          alignment: Alignment.topLeft,
293 294 295 296 297
          children: items,
          key: key,
          index: index,
        ),
      );
298 299
    }

300
    await tester.pumpWidget(buildFrame(0));
301
    expect(itemsTapped, isEmpty);
302
    await tester.tap(find.byKey(key));
303
    expect(itemsTapped, <int>[0]);
304

305
    await tester.pumpWidget(buildFrame(2));
306
    expect(itemsTapped, isEmpty);
307
    await tester.tap(find.byKey(key));
308
    expect(itemsTapped, <int>[2]);
Hans Muller's avatar
Hans Muller committed
309 310
  });

311
  testWidgets('Can set width and height', (WidgetTester tester) async {
312
    const Key key = Key('container');
313

314 315
    const BoxDecoration kBoxDecoration = BoxDecoration(
      color: Color(0xFF00FF00),
316 317
    );

318
    await tester.pumpWidget(
319
      Stack(
320
        textDirection: TextDirection.ltr,
321
        children: const <Widget>[
322
          Positioned(
323 324 325
            left: 10.0,
            width: 11.0,
            height: 12.0,
326
            child: DecoratedBox(key: key, decoration: kBoxDecoration),
327 328 329
          ),
        ],
      ),
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
    );

    Element box;
    RenderBox renderBox;
    StackParentData parentData;

    box = tester.element(find.byKey(key));
    renderBox = box.renderObject;
    parentData = renderBox.parentData;
    expect(parentData.top, isNull);
    expect(parentData.right, isNull);
    expect(parentData.bottom, isNull);
    expect(parentData.left, equals(10.0));
    expect(parentData.width, equals(11.0));
    expect(parentData.height, equals(12.0));
    expect(parentData.offset.dx, equals(10.0));
    expect(parentData.offset.dy, equals(0.0));
    expect(renderBox.size.width, equals(11.0));
    expect(renderBox.size.height, equals(12.0));

350
    await tester.pumpWidget(
351
      Stack(
352
        textDirection: TextDirection.ltr,
353
        children: const <Widget>[
354
          Positioned(
355 356 357
            right: 10.0,
            width: 11.0,
            height: 12.0,
358
            child: DecoratedBox(key: key, decoration: kBoxDecoration),
359 360 361
          ),
        ],
      ),
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
    );

    box = tester.element(find.byKey(key));
    renderBox = box.renderObject;
    parentData = renderBox.parentData;
    expect(parentData.top, isNull);
    expect(parentData.right, equals(10.0));
    expect(parentData.bottom, isNull);
    expect(parentData.left, isNull);
    expect(parentData.width, equals(11.0));
    expect(parentData.height, equals(12.0));
    expect(parentData.offset.dx, equals(779.0));
    expect(parentData.offset.dy, equals(0.0));
    expect(renderBox.size.width, equals(11.0));
    expect(renderBox.size.height, equals(12.0));
377 378
  });

379 380 381 382
  testWidgets('IndexedStack with null index', (WidgetTester tester) async {
    bool tapped;

    await tester.pumpWidget(
383
      Directionality(
384
        textDirection: TextDirection.ltr,
385 386
        child: Center(
          child: IndexedStack(
387 388
            index: null,
            children: <Widget>[
389
              GestureDetector(
390
                behavior: HitTestBehavior.opaque,
Ian Hickson's avatar
Ian Hickson committed
391
                onTap: () { tapped = true; },
392 393 394 395
                child: const SizedBox(
                  width: 200.0,
                  height: 200.0,
                ),
396
              ),
397 398
            ],
          ),
399 400 401 402 403
        ),
      ),
    );

    await tester.tap(find.byType(IndexedStack));
404
    final RenderBox box = tester.renderObject(find.byType(IndexedStack));
405 406 407 408
    expect(box.size, equals(const Size(200.0, 200.0)));
    expect(tapped, isNull);
  });

409 410
  testWidgets('Stack clip test', (WidgetTester tester) async {
    await tester.pumpWidget(
411
      Directionality(
412
        textDirection: TextDirection.ltr,
413 414
        child: Center(
          child: Stack(
415
            children: <Widget>[
416
              Container(
417 418 419
                width: 100.0,
                height: 100.0,
              ),
420
              Positioned(
421 422
                top: 0.0,
                left: 0.0,
423
                child: Container(
424 425 426 427 428 429 430 431
                  width: 200.0,
                  height: 200.0,
                ),
              ),
            ],
          ),
        ),
      ),
432 433 434
    );

    RenderBox box = tester.renderObject(find.byType(Stack));
435
    TestPaintingContext context = TestPaintingContext();
436 437 438 439
    box.paint(context, Offset.zero);
    expect(context.invocations.first.memberName, equals(#pushClipRect));

    await tester.pumpWidget(
440
      Directionality(
441
        textDirection: TextDirection.ltr,
442 443
        child: Center(
          child: Stack(
444 445
            overflow: Overflow.visible,
            children: <Widget>[
446
              Container(
447 448 449
                width: 100.0,
                height: 100.0,
              ),
450
              Positioned(
451 452
                top: 0.0,
                left: 0.0,
453
                child: Container(
454 455 456 457 458 459 460 461
                  width: 200.0,
                  height: 200.0,
                ),
              ),
            ],
          ),
        ),
      ),
462 463 464
    );

    box = tester.renderObject(find.byType(Stack));
465
    context = TestPaintingContext();
466 467 468
    box.paint(context, Offset.zero);
    expect(context.invocations.first.memberName, equals(#paintChild));
  });
469 470 471 472

  testWidgets('Stack sizing: default', (WidgetTester tester) async {
    final List<String> logs = <String>[];
    await tester.pumpWidget(
473
      Directionality(
474
        textDirection: TextDirection.ltr,
475 476
        child: Center(
          child: ConstrainedBox(
477 478 479 480 481 482
            constraints: const BoxConstraints(
              minWidth: 2.0,
              maxWidth: 3.0,
              minHeight: 5.0,
              maxHeight: 7.0,
            ),
483
            child: Stack(
484
              children: <Widget>[
485
                LayoutBuilder(
486 487 488 489 490 491 492
                  builder: (BuildContext context, BoxConstraints constraints) {
                    logs.add(constraints.toString());
                    return const Placeholder();
                  },
                ),
              ],
            ),
493 494 495 496 497 498 499 500 501 502
          ),
        ),
      ),
    );
    expect(logs, <String>['BoxConstraints(0.0<=w<=3.0, 0.0<=h<=7.0)']);
  });

  testWidgets('Stack sizing: explicit', (WidgetTester tester) async {
    final List<String> logs = <String>[];
    Widget buildStack(StackFit sizing) {
503
      return Directionality(
504
        textDirection: TextDirection.ltr,
505 506
        child: Center(
          child: ConstrainedBox(
507 508 509 510 511 512
            constraints: const BoxConstraints(
              minWidth: 2.0,
              maxWidth: 3.0,
              minHeight: 5.0,
              maxHeight: 7.0,
            ),
513
            child: Stack(
514 515
              fit: sizing,
              children: <Widget>[
516
                LayoutBuilder(
517 518 519 520 521 522 523
                  builder: (BuildContext context, BoxConstraints constraints) {
                    logs.add(constraints.toString());
                    return const Placeholder();
                  },
                ),
              ],
            ),
524 525 526 527 528 529 530 531 532 533 534 535 536 537
          ),
        ),
      );
    }
    await tester.pumpWidget(buildStack(StackFit.loose));
    logs.add('=1=');
    await tester.pumpWidget(buildStack(StackFit.expand));
    logs.add('=2=');
    await tester.pumpWidget(buildStack(StackFit.passthrough));
    expect(logs, <String>[
      'BoxConstraints(0.0<=w<=3.0, 0.0<=h<=7.0)',
      '=1=',
      'BoxConstraints(w=3.0, h=7.0)',
      '=2=',
538
      'BoxConstraints(2.0<=w<=3.0, 5.0<=h<=7.0)',
539 540
    ]);
  });
541 542

  testWidgets('Positioned.directional control test', (WidgetTester tester) async {
543
    final Key key = UniqueKey();
544
    await tester.pumpWidget(
545
      Directionality(
546
        textDirection: TextDirection.ltr,
547
        child: Stack(
548
          children: <Widget>[
549
            Positioned.directional(
550 551
              textDirection: TextDirection.rtl,
              start: 50.0,
552
              child: Container(key: key, width: 75.0, height: 175.0),
553 554
            ),
          ],
555
        ),
556 557
      ),
    );
558 559 560

    expect(tester.getTopLeft(find.byKey(key)), const Offset(675.0, 0.0));

561
    await tester.pumpWidget(
562
      Directionality(
563
        textDirection: TextDirection.ltr,
564
        child: Stack(
565
          children: <Widget>[
566
            Positioned.directional(
567 568
              textDirection: TextDirection.ltr,
              start: 50.0,
569
              child: Container(key: key, width: 75.0, height: 175.0),
570 571
            ),
          ],
572
        ),
573 574
      ),
    );
575 576 577 578 579

    expect(tester.getTopLeft(find.byKey(key)), const Offset(50.0, 0.0));
  });

  testWidgets('PositionedDirectional control test', (WidgetTester tester) async {
580
    final Key key = UniqueKey();
581
    await tester.pumpWidget(
582
      Directionality(
583
        textDirection: TextDirection.rtl,
584
        child: Stack(
585
          children: <Widget>[
586
            PositionedDirectional(
587
              start: 50.0,
588
              child: Container(key: key, width: 75.0, height: 175.0),
589 590 591 592 593 594 595 596 597
            ),
          ],
        ),
      )
    );

    expect(tester.getTopLeft(find.byKey(key)), const Offset(675.0, 0.0));

    await tester.pumpWidget(
598
      Directionality(
599
        textDirection: TextDirection.ltr,
600
        child: Stack(
601
          children: <Widget>[
602
            PositionedDirectional(
603
              start: 50.0,
604
              child: Container(key: key, width: 75.0, height: 175.0),
605 606 607 608 609 610 611 612
            ),
          ],
        ),
      )
    );

    expect(tester.getTopLeft(find.byKey(key)), const Offset(50.0, 0.0));
  });
Ian Hickson's avatar
Ian Hickson committed
613 614 615

  testWidgets('Can change the text direction of a Stack', (WidgetTester tester) async {
    await tester.pumpWidget(
616
      Stack(
617
        alignment: Alignment.center,
Ian Hickson's avatar
Ian Hickson committed
618 619 620
      ),
    );
    await tester.pumpWidget(
621
      Stack(
622
        alignment: AlignmentDirectional.topStart,
Ian Hickson's avatar
Ian Hickson committed
623 624 625 626
        textDirection: TextDirection.rtl,
      ),
    );
    await tester.pumpWidget(
627
      Stack(
628
        alignment: Alignment.center,
Ian Hickson's avatar
Ian Hickson committed
629 630 631
      ),
    );
  });
632 633 634

  testWidgets('Alignment with partially-positioned children', (WidgetTester tester) async {
    await tester.pumpWidget(
635
      Directionality(
636
        textDirection: TextDirection.rtl,
637
        child: Stack(
638
          alignment: Alignment.center,
639
          children: const <Widget>[
640 641 642 643 644 645 646 647 648
            SizedBox(width: 100.0, height: 100.0),
            Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
649 650 651 652
          ],
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
653 654 655 656 657 658 659 660 661
    expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(350.0, 250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0,   250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(350.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(0.0,   250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(350.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0));
662 663

    await tester.pumpWidget(
664
      Directionality(
665
        textDirection: TextDirection.ltr,
666
        child: Stack(
667
          alignment: Alignment.center,
668
          children: const <Widget>[
669 670 671 672 673 674 675 676 677
            SizedBox(width: 100.0, height: 100.0),
            Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
678 679 680 681
          ],
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
682 683 684 685 686 687 688 689 690
    expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(350.0, 250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0,   250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(350.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(0.0,   250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(350.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0));
691 692

    await tester.pumpWidget(
693
      Directionality(
694
        textDirection: TextDirection.ltr,
695
        child: Stack(
696
          alignment: Alignment.bottomRight,
697
          children: const <Widget>[
698 699 700 701 702 703 704 705 706
            SizedBox(width: 100.0, height: 100.0),
            Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
707 708 709 710
          ],
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
711 712 713 714 715 716 717 718 719
    expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0,   500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(700.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(0.0,   500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(700.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0));
720 721

    await tester.pumpWidget(
722
      Directionality(
723
        textDirection: TextDirection.ltr,
724
        child: Stack(
725
          alignment: Alignment.topLeft,
726
          children: const <Widget>[
727 728 729 730 731 732 733 734 735
            SizedBox(width: 100.0, height: 100.0),
            Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
            PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)),
736 737 738 739
          ],
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
740 741 742 743 744 745 746 747 748
    expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(0.0,   0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0,   0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(0.0,   0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(0.0,   500.0, 100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(0.0,   0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(700.0, 0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(0.0,   0.0,   100.0, 100.0));
    expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(0.0,   500.0, 100.0, 100.0));
749
  });
750
}