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

5 6
// @dart = 2.8

Ian Hickson's avatar
Ian Hickson committed
7 8 9 10 11
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

void main() {
12
  testWidgets('AnimatedPositioned.fromRect control test', (WidgetTester tester) async {
13
    final AnimatedPositioned positioned = AnimatedPositioned.fromRect(
Dan Field's avatar
Dan Field committed
14
      rect: const Rect.fromLTWH(7.0, 5.0, 12.0, 16.0),
15
      duration: const Duration(milliseconds: 200),
16
      child: Container(),
17 18 19 20 21 22 23 24 25
    );

    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);
  });

26
  testWidgets('AnimatedPositioned - basics (VISUAL)', (WidgetTester tester) async {
27
    final GlobalKey key = GlobalKey();
28 29 30

    RenderBox box;

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

47
    box = key.currentContext.findRenderObject() as RenderBox;
48
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0)));
49

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

52
    box = key.currentContext.findRenderObject() as RenderBox;
53
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0)));
54

55
    await tester.pumpWidget(
56
      Stack(
57
        textDirection: TextDirection.ltr,
58
        children: <Widget>[
59 60
          AnimatedPositioned(
            child: Container(key: key),
61 62 63 64
            left: 37.0,
            top: 31.0,
            width: 59.0,
            height: 71.0,
65 66 67 68 69 70
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
    );

71 72
    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);
73

74
    box = key.currentContext.findRenderObject() as RenderBox;
75 76 77 78
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));

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

79
    box = key.currentContext.findRenderObject() as RenderBox;
80 81 82 83
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

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

84
    box = key.currentContext.findRenderObject() as RenderBox;
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    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',
      ),
    );
  });

108
  testWidgets('AnimatedPositionedDirectional - basics (LTR)', (WidgetTester tester) async {
109
    final GlobalKey key = GlobalKey();
110 111 112 113

    RenderBox box;

    await tester.pumpWidget(
114
      Directionality(
115
        textDirection: TextDirection.ltr,
116
        child: Stack(
117
          children: <Widget>[
118 119
            AnimatedPositionedDirectional(
              child: Container(key: key),
120 121 122 123 124 125 126 127 128
              start: 50.0,
              top: 30.0,
              width: 70.0,
              height: 110.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
129 130
    );

131
    box = key.currentContext.findRenderObject() as RenderBox;
132
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0 + 70.0 / 2.0, 30.0 + 110.0 / 2.0)));
133

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

136
    box = key.currentContext.findRenderObject() as RenderBox;
137 138 139
    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(
140
      Directionality(
141
        textDirection: TextDirection.ltr,
142
        child: Stack(
143
          children: <Widget>[
144 145
            AnimatedPositionedDirectional(
              child: Container(key: key),
146 147 148 149 150 151 152 153 154 155 156
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

157 158
    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);
159

160
    box = key.currentContext.findRenderObject() as RenderBox;
161
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));
162

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

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

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

170
    box = key.currentContext.findRenderObject() as RenderBox;
171
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(last));
172 173 174

    expect(box, hasAGoodToStringDeep);
    expect(
175
      box.toStringDeep(minLevel: DiagnosticLevel.info),
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
      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
192 193
  });

194
  testWidgets('AnimatedPositionedDirectional - basics (RTL)', (WidgetTester tester) async {
195
    final GlobalKey key = GlobalKey();
196 197 198 199

    RenderBox box;

    await tester.pumpWidget(
200
      Directionality(
201
        textDirection: TextDirection.rtl,
202
        child: Stack(
203
          children: <Widget>[
204 205
            AnimatedPositionedDirectional(
              child: Container(key: key),
206 207 208 209 210 211 212 213 214 215 216
              start: 50.0,
              top: 30.0,
              width: 70.0,
              height: 110.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

217
    box = key.currentContext.findRenderObject() as RenderBox;
218 219 220 221
    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));

222
    box = key.currentContext.findRenderObject() as RenderBox;
223 224 225
    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(
226
      Directionality(
227
        textDirection: TextDirection.rtl,
228
        child: Stack(
229
          children: <Widget>[
230 231
            AnimatedPositionedDirectional(
              child: Container(key: key),
232 233 234 235 236 237 238 239 240 241 242
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

243 244
    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);
245

246
    box = key.currentContext.findRenderObject() as RenderBox;
247 248 249 250
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));

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

251
    box = key.currentContext.findRenderObject() as RenderBox;
252 253 254 255
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

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

256
    box = key.currentContext.findRenderObject() as RenderBox;
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    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'
      ),
    );
  });

280
  testWidgets('AnimatedPositioned - interrupted animation (VISUAL)', (WidgetTester tester) async {
281
    final GlobalKey key = GlobalKey();
282 283 284

    RenderBox box;

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

301
    box = key.currentContext.findRenderObject() as RenderBox;
302
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
303

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

306
    box = key.currentContext.findRenderObject() as RenderBox;
307
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
308

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

325
    box = key.currentContext.findRenderObject() as RenderBox;
326
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
327

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

330
    box = key.currentContext.findRenderObject() as RenderBox;
331
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));
332

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

349
    box = key.currentContext.findRenderObject() as RenderBox;
350
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));
351

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

354
    box = key.currentContext.findRenderObject() as RenderBox;
355
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(150.0, 150.0)));
356

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

359
    box = key.currentContext.findRenderObject() as RenderBox;
360
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(200.0, 200.0)));
Ian Hickson's avatar
Ian Hickson committed
361 362
  });

363
  testWidgets('AnimatedPositioned - switching variables (VISUAL)', (WidgetTester tester) async {
364
    final GlobalKey key = GlobalKey();
365 366 367

    RenderBox box;

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

384
    box = key.currentContext.findRenderObject() as RenderBox;
385
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
386

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

389
    box = key.currentContext.findRenderObject() as RenderBox;
390
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));
391

392
    await tester.pumpWidget(
393
      Stack(
394
        textDirection: TextDirection.ltr,
395
        children: <Widget>[
396 397
          AnimatedPositioned(
            child: Container(key: key),
398 399 400 401
            left: 0.0,
            top: 100.0,
            right: 100.0, // 700.0 from the left
            height: 100.0,
402 403 404 405 406 407
            duration: const Duration(seconds: 2),
          ),
        ],
      ),
    );

408
    box = key.currentContext.findRenderObject() as RenderBox;
409 410 411 412
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 50.0)));

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

413
    box = key.currentContext.findRenderObject() as RenderBox;
414 415 416 417
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 100.0)));

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

418
    box = key.currentContext.findRenderObject() as RenderBox;
419 420 421 422
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 150.0)));
  });

  testWidgets('AnimatedPositionedDirectional - interrupted animation (LTR)', (WidgetTester tester) async {
423
    final GlobalKey key = GlobalKey();
424 425 426 427

    RenderBox box;

    await tester.pumpWidget(
428
      Directionality(
429
        textDirection: TextDirection.ltr,
430
        child: Stack(
431
          children: <Widget>[
432 433
            AnimatedPositionedDirectional(
              child: Container(key: key),
434 435 436 437 438 439 440 441 442 443 444
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

445
    box = key.currentContext.findRenderObject() as RenderBox;
446 447 448 449
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

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

450
    box = key.currentContext.findRenderObject() as RenderBox;
451 452 453
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

    await tester.pumpWidget(
454
      Directionality(
455
        textDirection: TextDirection.ltr,
456
        child: Stack(
457
          children: <Widget>[
458 459
            AnimatedPositionedDirectional(
              child: Container(key: key),
460 461 462 463 464 465 466 467 468 469 470
              start: 100.0,
              top: 100.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

471
    box = key.currentContext.findRenderObject() as RenderBox;
472 473 474 475
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

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

476
    box = key.currentContext.findRenderObject() as RenderBox;
477 478 479
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));

    await tester.pumpWidget(
480
      Directionality(
481
        textDirection: TextDirection.ltr,
482
        child: Stack(
483
          children: <Widget>[
484 485
            AnimatedPositionedDirectional(
              child: Container(key: key),
486 487 488 489 490 491 492 493 494 495 496
              start: 150.0,
              top: 150.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

497
    box = key.currentContext.findRenderObject() as RenderBox;
498 499 500 501
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));

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

502
    box = key.currentContext.findRenderObject() as RenderBox;
503 504 505 506
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(150.0, 150.0)));

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

507
    box = key.currentContext.findRenderObject() as RenderBox;
508 509 510 511
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(200.0, 200.0)));
  });

  testWidgets('AnimatedPositionedDirectional - switching variables (LTR)', (WidgetTester tester) async {
512
    final GlobalKey key = GlobalKey();
513 514 515 516

    RenderBox box;

    await tester.pumpWidget(
517
      Directionality(
518
        textDirection: TextDirection.ltr,
519
        child: Stack(
520
          children: <Widget>[
521 522
            AnimatedPositionedDirectional(
              child: Container(key: key),
523 524 525 526 527 528 529 530 531 532 533
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

534
    box = key.currentContext.findRenderObject() as RenderBox;
535 536 537 538
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

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

539
    box = key.currentContext.findRenderObject() as RenderBox;
540 541 542
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

    await tester.pumpWidget(
543
      Directionality(
544
        textDirection: TextDirection.ltr,
545
        child: Stack(
546
          children: <Widget>[
547 548
            AnimatedPositionedDirectional(
              child: Container(key: key),
549 550 551 552 553 554 555 556 557
              start: 0.0,
              top: 100.0,
              end: 100.0, // 700.0 from the start
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
558 559
    );

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

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

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

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

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

574
  testWidgets('AnimatedPositionedDirectional - interrupted animation (RTL)', (WidgetTester tester) async {
575
    final GlobalKey key = GlobalKey();
576 577 578 579

    RenderBox box;

    await tester.pumpWidget(
580
      Directionality(
581
        textDirection: TextDirection.rtl,
582
        child: Stack(
583
          children: <Widget>[
584 585
            AnimatedPositionedDirectional(
              child: Container(key: key),
586 587 588 589 590 591 592 593 594 595 596
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

597
    box = key.currentContext.findRenderObject() as RenderBox;
598 599 600 601
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

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

602
    box = key.currentContext.findRenderObject() as RenderBox;
603 604 605
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

    await tester.pumpWidget(
606
      Directionality(
607
        textDirection: TextDirection.rtl,
608
        child: Stack(
609
          children: <Widget>[
610 611
            AnimatedPositionedDirectional(
              child: Container(key: key),
612 613 614 615 616 617 618 619 620 621 622
              start: 100.0,
              top: 100.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

623
    box = key.currentContext.findRenderObject() as RenderBox;
624 625 626 627
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

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

628
    box = key.currentContext.findRenderObject() as RenderBox;
629 630 631
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(700.0, 100.0)));

    await tester.pumpWidget(
632
      Directionality(
633
        textDirection: TextDirection.rtl,
634
        child: Stack(
635
          children: <Widget>[
636 637
            AnimatedPositionedDirectional(
              child: Container(key: key),
638 639 640 641 642 643 644 645 646 647 648
              start: 150.0,
              top: 150.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

649
    box = key.currentContext.findRenderObject() as RenderBox;
650 651 652 653
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(700.0, 100.0)));

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

654
    box = key.currentContext.findRenderObject() as RenderBox;
655 656 657 658
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(650.0, 150.0)));

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

659
    box = key.currentContext.findRenderObject() as RenderBox;
660 661 662 663
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(600.0, 200.0)));
  });

  testWidgets('AnimatedPositionedDirectional - switching variables (RTL)', (WidgetTester tester) async {
664
    final GlobalKey key = GlobalKey();
665 666 667 668

    RenderBox box;

    await tester.pumpWidget(
669
      Directionality(
670
        textDirection: TextDirection.rtl,
671
        child: Stack(
672
          children: <Widget>[
673 674
            AnimatedPositionedDirectional(
              child: Container(key: key),
675 676 677 678 679 680 681 682 683 684 685
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

686
    box = key.currentContext.findRenderObject() as RenderBox;
687 688 689 690
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

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

691
    box = key.currentContext.findRenderObject() as RenderBox;
692 693 694
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

    await tester.pumpWidget(
695
      Directionality(
696
        textDirection: TextDirection.rtl,
697
        child: Stack(
698
          children: <Widget>[
699 700
            AnimatedPositionedDirectional(
              child: Container(key: key),
701 702 703 704 705 706 707 708 709 710 711
              start: 0.0,
              top: 100.0,
              end: 100.0, // 700.0 from the start
              height: 100.0,
              duration: const Duration(seconds: 2),
            ),
          ],
        ),
      ),
    );

712
    box = key.currentContext.findRenderObject() as RenderBox;
713 714 715 716
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 50.0)));

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

717
    box = key.currentContext.findRenderObject() as RenderBox;
718 719 720 721
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 100.0)));

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

722
    box = key.currentContext.findRenderObject() as RenderBox;
723 724 725
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 150.0)));
  });

Ian Hickson's avatar
Ian Hickson committed
726
}