animated_positioned_test.dart 22.9 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4 5 6 7 8 9
// 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.

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

void main() {
10
  testWidgets('AnimatedPositioned.fromRect control test', (WidgetTester tester) async {
11
    final AnimatedPositioned positioned = new AnimatedPositioned.fromRect(
12 13 14 15 16 17 18 19 20 21 22
      rect: new Rect.fromLTWH(7.0, 5.0, 12.0, 16.0),
      duration: const Duration(milliseconds: 200),
    );

    expect(positioned.left, equals(7.0));
    expect(positioned.top, equals(5.0));
    expect(positioned.width, equals(12.0));
    expect(positioned.height, equals(16.0));
    expect(positioned, hasOneLineDescription);
  });

23
  testWidgets('AnimatedPositioned - basics (VISUAL)', (WidgetTester tester) async {
24
    final GlobalKey key = new GlobalKey();
25 26 27

    RenderBox box;

28
    await tester.pumpWidget(
29
      new Stack(
30
        textDirection: TextDirection.ltr,
31 32 33 34 35 36 37
        children: <Widget>[
          new AnimatedPositioned(
            child: new Container(key: key),
            left: 50.0,
            top: 30.0,
            width: 70.0,
            height: 110.0,
38 39 40 41
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
42 43 44
    );

    box = key.currentContext.findRenderObject();
45
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0)));
46

47
    await tester.pump(const Duration(seconds: 1));
48 49

    box = key.currentContext.findRenderObject();
50
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0)));
51

52
    await tester.pumpWidget(
53
      new Stack(
54
        textDirection: TextDirection.ltr,
55 56 57 58 59 60 61
        children: <Widget>[
          new AnimatedPositioned(
            child: new Container(key: key),
            left: 37.0,
            top: 31.0,
            width: 59.0,
            height: 71.0,
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
    );

    const Offset first = const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0);
    const Offset last = const Offset(37.0 + 59.0 / 2.0, 31.0 + 71.0 / 2.0);

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(last));

    expect(box, hasAGoodToStringDeep);
    expect(
      box.toStringDeep(minLevel: DiagnosticLevel.info),
      equalsIgnoringHashCodes(
        'RenderLimitedBox#00000\n'
        ' │ parentData: top=31.0; left=37.0; width=59.0; height=71.0;\n'
        ' │   offset=Offset(37.0, 31.0) (can use size)\n'
        ' │ constraints: BoxConstraints(w=59.0, h=71.0)\n'
        ' │ size: Size(59.0, 71.0)\n'
        ' │ maxWidth: 0.0\n'
        ' │ maxHeight: 0.0\n'
        ' │\n'
        ' └─child: RenderConstrainedBox#00000\n'
        '     parentData: <none> (can use size)\n'
        '     constraints: BoxConstraints(w=59.0, h=71.0)\n'
        '     size: Size(59.0, 71.0)\n'
        '     additionalConstraints: BoxConstraints(biggest)\n',
      ),
    );
  });

105
  testWidgets('AnimatedPositionedDirectional - basics (LTR)', (WidgetTester tester) async {
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    final GlobalKey key = new GlobalKey();

    RenderBox box;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 50.0,
              top: 30.0,
              width: 70.0,
              height: 110.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
126 127 128
    );

    box = key.currentContext.findRenderObject();
129
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0)));
130

131
    await tester.pump(const Duration(seconds: 1));
132 133

    box = key.currentContext.findRenderObject();
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    const Offset first = const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0);
    const Offset last = const Offset(37.0 + 59.0 / 2.0, 31.0 + 71.0 / 2.0);

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));
159

160
    await tester.pump(const Duration(seconds: 1));
161 162

    box = key.currentContext.findRenderObject();
163 164 165 166 167 168
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(last));
169 170 171

    expect(box, hasAGoodToStringDeep);
    expect(
172
      box.toStringDeep(minLevel: DiagnosticLevel.info),
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
      equalsIgnoringHashCodes(
        'RenderLimitedBox#00000\n'
        ' │ parentData: top=31.0; left=37.0; width=59.0; height=71.0;\n'
        ' │   offset=Offset(37.0, 31.0) (can use size)\n'
        ' │ constraints: BoxConstraints(w=59.0, h=71.0)\n'
        ' │ size: Size(59.0, 71.0)\n'
        ' │ maxWidth: 0.0\n'
        ' │ maxHeight: 0.0\n'
        ' │\n'
        ' └─child: RenderConstrainedBox#00000\n'
        '     parentData: <none> (can use size)\n'
        '     constraints: BoxConstraints(w=59.0, h=71.0)\n'
        '     size: Size(59.0, 71.0)\n'
        '     additionalConstraints: BoxConstraints(biggest)\n',
      ),
    );
Ian Hickson's avatar
Ian Hickson committed
189 190
  });

191
  testWidgets('AnimatedPositionedDirectional - basics (RTL)', (WidgetTester tester) async {
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    final GlobalKey key = new GlobalKey();

    RenderBox box;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 50.0,
              top: 30.0,
              width: 70.0,
              height: 110.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(800.0 - 50.0 - 70.0 / 2.0, 30.0 + 110.0 / 2.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(800.0 - 50.0 - 70.0 / 2.0, 30.0 + 110.0 / 2.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    const Offset first = const Offset(800.0 - 50.0 - 70.0 / 2.0, 30.0 + 110.0 / 2.0);
    const Offset last = const Offset(800.0 - 37.0 - 59.0 / 2.0, 31.0 + 71.0 / 2.0);

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(last));

    expect(box, hasAGoodToStringDeep);
    expect(
      box.toStringDeep(minLevel: DiagnosticLevel.info),
      equalsIgnoringHashCodes(
        'RenderLimitedBox#00000\n'
        ' │ parentData: top=31.0; right=37.0; width=59.0; height=71.0;\n'
        ' │   offset=Offset(704.0, 31.0) (can use size)\n'
        ' │ constraints: BoxConstraints(w=59.0, h=71.0)\n'
        ' │ size: Size(59.0, 71.0)\n'
        ' │ maxWidth: 0.0\n'
        ' │ maxHeight: 0.0\n'
        ' │\n'
        ' └─child: RenderConstrainedBox#00000\n'
        '     parentData: <none> (can use size)\n'
        '     constraints: BoxConstraints(w=59.0, h=71.0)\n'
        '     size: Size(59.0, 71.0)\n'
        '     additionalConstraints: BoxConstraints(biggest)\n'
      ),
    );
  });

277
  testWidgets('AnimatedPositioned - interrupted animation (VISUAL)', (WidgetTester tester) async {
278
    final GlobalKey key = new GlobalKey();
279 280 281

    RenderBox box;

282
    await tester.pumpWidget(
283
      new Stack(
284
        textDirection: TextDirection.ltr,
285 286 287 288 289 290 291
        children: <Widget>[
          new AnimatedPositioned(
            child: new Container(key: key),
            left: 0.0,
            top: 0.0,
            width: 100.0,
            height: 100.0,
292 293 294 295
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
296 297 298
    );

    box = key.currentContext.findRenderObject();
299
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
300

301
    await tester.pump(const Duration(seconds: 1));
302 303

    box = key.currentContext.findRenderObject();
304
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
305

306
    await tester.pumpWidget(
307
      new Stack(
308
        textDirection: TextDirection.ltr,
309 310 311 312 313 314 315
        children: <Widget>[
          new AnimatedPositioned(
            child: new Container(key: key),
            left: 100.0,
            top: 100.0,
            width: 100.0,
            height: 100.0,
316 317 318 319
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
320 321 322
    );

    box = key.currentContext.findRenderObject();
323
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
324

325
    await tester.pump(const Duration(seconds: 1));
326 327

    box = key.currentContext.findRenderObject();
328
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));
329

330
    await tester.pumpWidget(
331
      new Stack(
332
        textDirection: TextDirection.ltr,
333 334 335 336 337 338 339
        children: <Widget>[
          new AnimatedPositioned(
            child: new Container(key: key),
            left: 150.0,
            top: 150.0,
            width: 100.0,
            height: 100.0,
340 341 342 343
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
344 345 346
    );

    box = key.currentContext.findRenderObject();
347
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));
348

349
    await tester.pump(const Duration(seconds: 1));
350 351

    box = key.currentContext.findRenderObject();
352
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(150.0, 150.0)));
353

354
    await tester.pump(const Duration(seconds: 1));
355 356

    box = key.currentContext.findRenderObject();
357
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(200.0, 200.0)));
Ian Hickson's avatar
Ian Hickson committed
358 359
  });

360
  testWidgets('AnimatedPositioned - switching variables (VISUAL)', (WidgetTester tester) async {
361
    final GlobalKey key = new GlobalKey();
362 363 364

    RenderBox box;

365
    await tester.pumpWidget(
366
      new Stack(
367
        textDirection: TextDirection.ltr,
368 369 370 371 372 373 374
        children: <Widget>[
          new AnimatedPositioned(
            child: new Container(key: key),
            left: 0.0,
            top: 0.0,
            width: 100.0,
            height: 100.0,
375 376 377 378
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
379 380 381
    );

    box = key.currentContext.findRenderObject();
382
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
383

384
    await tester.pump(const Duration(seconds: 1));
385 386

    box = key.currentContext.findRenderObject();
387
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
388

389
    await tester.pumpWidget(
390
      new Stack(
391
        textDirection: TextDirection.ltr,
392 393 394 395 396 397 398
        children: <Widget>[
          new AnimatedPositioned(
            child: new Container(key: key),
            left: 0.0,
            top: 100.0,
            right: 100.0, // 700.0 from the left
            height: 100.0,
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 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 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 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 551 552 553 554
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 100.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 150.0)));
  });

  testWidgets('AnimatedPositionedDirectional - interrupted animation (LTR)', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();

    RenderBox box;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 100.0,
              top: 100.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 150.0,
              top: 150.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(150.0, 150.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(200.0, 200.0)));
  });

  testWidgets('AnimatedPositionedDirectional - switching variables (LTR)', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();

    RenderBox box;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 0.0,
              top: 100.0,
              end: 100.0, // 700.0 from the start
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
555 556 557
    );

    box = key.currentContext.findRenderObject();
558
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 50.0)));
559

560
    await tester.pump(const Duration(seconds: 1));
561 562

    box = key.currentContext.findRenderObject();
563
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 100.0)));
564

565
    await tester.pump(const Duration(seconds: 1));
566 567

    box = key.currentContext.findRenderObject();
568
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 150.0)));
Ian Hickson's avatar
Ian Hickson committed
569 570
  });

571 572 573 574 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 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 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 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
  testWidgets('AnimatedPositionedDirectional - interrupted animation (RTL)', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();

    RenderBox box;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 100.0,
              top: 100.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(700.0, 100.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 150.0,
              top: 150.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(700.0, 100.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(650.0, 150.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(600.0, 200.0)));
  });

  testWidgets('AnimatedPositionedDirectional - switching variables (RTL)', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();

    RenderBox box;

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Stack(
          children: <Widget>[
            new AnimatedPositionedDirectional(
              child: new Container(key: key),
              start: 0.0,
              top: 100.0,
              end: 100.0, // 700.0 from the start
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 50.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 100.0)));

    await tester.pump(const Duration(seconds: 1));

    box = key.currentContext.findRenderObject();
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 150.0)));
  });

Ian Hickson's avatar
Ian Hickson committed
723
}