animated_positioned_test.dart 22.5 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 12
    final AnimatedPositioned positioned = AnimatedPositioned.fromRect(
      rect: Rect.fromLTWH(7.0, 5.0, 12.0, 16.0),
13 14 15 16 17 18 19 20 21 22
      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 = GlobalKey();
25 26 27

    RenderBox box;

28
    await tester.pumpWidget(
29
      Stack(
30
        textDirection: TextDirection.ltr,
31
        children: <Widget>[
32 33
          AnimatedPositioned(
            child: Container(key: key),
34 35 36 37
            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
      Stack(
54
        textDirection: TextDirection.ltr,
55
        children: <Widget>[
56 57
          AnimatedPositioned(
            child: Container(key: key),
58 59 60 61
            left: 37.0,
            top: 31.0,
            width: 59.0,
            height: 71.0,
62 63 64 65 66 67
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
    );

68 69
    const Offset first = Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0);
    const Offset last = Offset(37.0 + 59.0 / 2.0, 31.0 + 71.0 / 2.0);
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

    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
    final GlobalKey key = GlobalKey();
107 108 109 110

    RenderBox box;

    await tester.pumpWidget(
111
      Directionality(
112
        textDirection: TextDirection.ltr,
113
        child: Stack(
114
          children: <Widget>[
115 116
            AnimatedPositionedDirectional(
              child: Container(key: key),
117 118 119 120 121 122 123 124 125
              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
    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(
137
      Directionality(
138
        textDirection: TextDirection.ltr,
139
        child: Stack(
140
          children: <Widget>[
141 142
            AnimatedPositionedDirectional(
              child: Container(key: key),
143 144 145 146 147 148 149 150 151 152 153
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

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

    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
    final GlobalKey key = GlobalKey();
193 194 195 196

    RenderBox box;

    await tester.pumpWidget(
197
      Directionality(
198
        textDirection: TextDirection.rtl,
199
        child: Stack(
200
          children: <Widget>[
201 202
            AnimatedPositionedDirectional(
              child: Container(key: key),
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
              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(
223
      Directionality(
224
        textDirection: TextDirection.rtl,
225
        child: Stack(
226
          children: <Widget>[
227 228
            AnimatedPositionedDirectional(
              child: Container(key: key),
229 230 231 232 233 234 235 236 237 238 239
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

240 241
    const Offset first = Offset(800.0 - 50.0 - 70.0 / 2.0, 30.0 + 110.0 / 2.0);
    const Offset last = Offset(800.0 - 37.0 - 59.0 / 2.0, 31.0 + 71.0 / 2.0);
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

    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 = GlobalKey();
279 280 281

    RenderBox box;

282
    await tester.pumpWidget(
283
      Stack(
284
        textDirection: TextDirection.ltr,
285
        children: <Widget>[
286 287
          AnimatedPositioned(
            child: Container(key: key),
288 289 290 291
            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
      Stack(
308
        textDirection: TextDirection.ltr,
309
        children: <Widget>[
310 311
          AnimatedPositioned(
            child: Container(key: key),
312 313 314 315
            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
      Stack(
332
        textDirection: TextDirection.ltr,
333
        children: <Widget>[
334 335
          AnimatedPositioned(
            child: Container(key: key),
336 337 338 339
            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 = GlobalKey();
362 363 364

    RenderBox box;

365
    await tester.pumpWidget(
366
      Stack(
367
        textDirection: TextDirection.ltr,
368
        children: <Widget>[
369 370
          AnimatedPositioned(
            child: Container(key: key),
371 372 373 374
            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
      Stack(
391
        textDirection: TextDirection.ltr,
392
        children: <Widget>[
393 394
          AnimatedPositioned(
            child: Container(key: key),
395 396 397 398
            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
            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 {
420
    final GlobalKey key = GlobalKey();
421 422 423 424

    RenderBox box;

    await tester.pumpWidget(
425
      Directionality(
426
        textDirection: TextDirection.ltr,
427
        child: Stack(
428
          children: <Widget>[
429 430
            AnimatedPositionedDirectional(
              child: Container(key: key),
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
              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(
451
      Directionality(
452
        textDirection: TextDirection.ltr,
453
        child: Stack(
454
          children: <Widget>[
455 456
            AnimatedPositionedDirectional(
              child: Container(key: key),
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
              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(
477
      Directionality(
478
        textDirection: TextDirection.ltr,
479
        child: Stack(
480
          children: <Widget>[
481 482
            AnimatedPositionedDirectional(
              child: Container(key: key),
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
              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 {
509
    final GlobalKey key = GlobalKey();
510 511 512 513

    RenderBox box;

    await tester.pumpWidget(
514
      Directionality(
515
        textDirection: TextDirection.ltr,
516
        child: Stack(
517
          children: <Widget>[
518 519
            AnimatedPositionedDirectional(
              child: Container(key: key),
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
              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(
540
      Directionality(
541
        textDirection: TextDirection.ltr,
542
        child: Stack(
543
          children: <Widget>[
544 545
            AnimatedPositionedDirectional(
              child: Container(key: key),
546 547 548 549 550 551 552 553 554
              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
  testWidgets('AnimatedPositionedDirectional - interrupted animation (RTL)', (WidgetTester tester) async {
572
    final GlobalKey key = GlobalKey();
573 574 575 576

    RenderBox box;

    await tester.pumpWidget(
577
      Directionality(
578
        textDirection: TextDirection.rtl,
579
        child: Stack(
580
          children: <Widget>[
581 582
            AnimatedPositionedDirectional(
              child: Container(key: key),
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
              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(
603
      Directionality(
604
        textDirection: TextDirection.rtl,
605
        child: Stack(
606
          children: <Widget>[
607 608
            AnimatedPositionedDirectional(
              child: Container(key: key),
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
              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(
629
      Directionality(
630
        textDirection: TextDirection.rtl,
631
        child: Stack(
632
          children: <Widget>[
633 634
            AnimatedPositionedDirectional(
              child: Container(key: key),
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
              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 {
661
    final GlobalKey key = GlobalKey();
662 663 664 665

    RenderBox box;

    await tester.pumpWidget(
666
      Directionality(
667
        textDirection: TextDirection.rtl,
668
        child: Stack(
669
          children: <Widget>[
670 671
            AnimatedPositionedDirectional(
              child: Container(key: key),
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
              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(
692
      Directionality(
693
        textDirection: TextDirection.rtl,
694
        child: Stack(
695
          children: <Widget>[
696 697
            AnimatedPositionedDirectional(
              child: Container(key: key),
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
              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
}