animated_positioned_test.dart 23.3 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 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
6
import 'package:flutter_test/flutter_test.dart';
Ian Hickson's avatar
Ian Hickson committed
7 8

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

    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
          AnimatedPositioned(
33 34 35 36
            left: 50.0,
            top: 30.0,
            width: 70.0,
            height: 110.0,
37
            duration: const Duration(seconds: 2),
38
            child: Container(key: key),
39 40 41
          ),
        ],
      ),
42 43
    );

44
    box = key.currentContext!.findRenderObject()! as RenderBox;
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()! as RenderBox;
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
          AnimatedPositioned(
57 58 59 60
            left: 37.0,
            top: 31.0,
            width: 59.0,
            height: 71.0,
61
            duration: const Duration(seconds: 2),
62
            child: Container(key: key),
63 64 65 66 67
          ),
        ],
      ),
    );

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
    box = key.currentContext!.findRenderObject()! as RenderBox;
72 73 74 75
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));

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

76
    box = key.currentContext!.findRenderObject()! as RenderBox;
77 78 79 80
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

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

81
    box = key.currentContext!.findRenderObject()! as RenderBox;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    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
            AnimatedPositionedDirectional(
116 117 118 119 120
              start: 50.0,
              top: 30.0,
              width: 70.0,
              height: 110.0,
              duration: const Duration(seconds: 2),
121
              child: Container(key: key),
122 123 124 125
            ),
          ],
        ),
      ),
126 127
    );

128
    box = key.currentContext!.findRenderObject()! as RenderBox;
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()! as RenderBox;
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
            AnimatedPositionedDirectional(
142 143 144 145 146
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
147
              child: Container(key: key),
148 149 150 151 152 153
            ),
          ],
        ),
      ),
    );

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
    box = key.currentContext!.findRenderObject()! as RenderBox;
158
    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()! as RenderBox;
163 164 165 166
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

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

167
    box = key.currentContext!.findRenderObject()! as RenderBox;
168
    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
            AnimatedPositionedDirectional(
202 203 204 205 206
              start: 50.0,
              top: 30.0,
              width: 70.0,
              height: 110.0,
              duration: const Duration(seconds: 2),
207
              child: Container(key: key),
208 209 210 211 212 213
            ),
          ],
        ),
      ),
    );

214
    box = key.currentContext!.findRenderObject()! as RenderBox;
215 216 217 218
    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));

219
    box = key.currentContext!.findRenderObject()! as RenderBox;
220 221 222
    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
            AnimatedPositionedDirectional(
228 229 230 231 232
              start: 37.0,
              top: 31.0,
              width: 59.0,
              height: 71.0,
              duration: const Duration(seconds: 2),
233
              child: Container(key: key),
234 235 236 237 238 239
            ),
          ],
        ),
      ),
    );

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
    box = key.currentContext!.findRenderObject()! as RenderBox;
244 245 246 247
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(first));

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

248
    box = key.currentContext!.findRenderObject()! as RenderBox;
249 250 251 252
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(Offset.lerp(first, last, 0.5)));

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

253
    box = key.currentContext!.findRenderObject()! as RenderBox;
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
    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'
272
        '     additionalConstraints: BoxConstraints(biggest)\n',
273 274 275 276
      ),
    );
  });

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
          AnimatedPositioned(
287 288 289 290
            left: 0.0,
            top: 0.0,
            width: 100.0,
            height: 100.0,
291
            duration: const Duration(seconds: 2),
292
            child: Container(key: key),
293 294 295
          ),
        ],
      ),
296 297
    );

298
    box = key.currentContext!.findRenderObject()! as RenderBox;
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()! as RenderBox;
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
          AnimatedPositioned(
311 312 313 314
            left: 100.0,
            top: 100.0,
            width: 100.0,
            height: 100.0,
315
            duration: const Duration(seconds: 2),
316
            child: Container(key: key),
317 318 319
          ),
        ],
      ),
320 321
    );

322
    box = key.currentContext!.findRenderObject()! as RenderBox;
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()! as RenderBox;
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
          AnimatedPositioned(
335 336 337 338
            left: 150.0,
            top: 150.0,
            width: 100.0,
            height: 100.0,
339
            duration: const Duration(seconds: 2),
340
            child: Container(key: key),
341 342 343
          ),
        ],
      ),
344 345
    );

346
    box = key.currentContext!.findRenderObject()! as RenderBox;
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()! as RenderBox;
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()! as RenderBox;
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
          AnimatedPositioned(
370 371 372 373
            left: 0.0,
            top: 0.0,
            width: 100.0,
            height: 100.0,
374
            duration: const Duration(seconds: 2),
375
            child: Container(key: key),
376 377 378
          ),
        ],
      ),
379 380
    );

381
    box = key.currentContext!.findRenderObject()! as RenderBox;
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()! as RenderBox;
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
          AnimatedPositioned(
394 395 396 397
            left: 0.0,
            top: 100.0,
            right: 100.0, // 700.0 from the left
            height: 100.0,
398
            duration: const Duration(seconds: 2),
399
            child: Container(key: key),
400 401 402 403 404
          ),
        ],
      ),
    );

405
    box = key.currentContext!.findRenderObject()! as RenderBox;
406 407 408 409
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 50.0)));

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

410
    box = key.currentContext!.findRenderObject()! as RenderBox;
411 412 413 414
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(350.0, 100.0)));

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

415
    box = key.currentContext!.findRenderObject()! as RenderBox;
416 417 418 419
    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
            AnimatedPositionedDirectional(
430 431 432 433 434
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
435
              child: Container(key: key),
436 437 438 439 440 441
            ),
          ],
        ),
      ),
    );

442
    box = key.currentContext!.findRenderObject()! as RenderBox;
443 444 445 446
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

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

447
    box = key.currentContext!.findRenderObject()! as RenderBox;
448 449 450
    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
            AnimatedPositionedDirectional(
456 457 458 459 460
              start: 100.0,
              top: 100.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
461
              child: Container(key: key),
462 463 464 465 466 467
            ),
          ],
        ),
      ),
    );

468
    box = key.currentContext!.findRenderObject()! as RenderBox;
469 470 471 472
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

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

473
    box = key.currentContext!.findRenderObject()! as RenderBox;
474 475 476
    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
            AnimatedPositionedDirectional(
482 483 484 485 486
              start: 150.0,
              top: 150.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
487
              child: Container(key: key),
488 489 490 491 492 493
            ),
          ],
        ),
      ),
    );

494
    box = key.currentContext!.findRenderObject()! as RenderBox;
495 496 497 498
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(100.0, 100.0)));

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

499
    box = key.currentContext!.findRenderObject()! as RenderBox;
500 501 502 503
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(150.0, 150.0)));

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

504
    box = key.currentContext!.findRenderObject()! as RenderBox;
505 506 507 508
    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
            AnimatedPositionedDirectional(
519 520 521 522 523
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
524
              child: Container(key: key),
525 526 527 528 529 530
            ),
          ],
        ),
      ),
    );

531
    box = key.currentContext!.findRenderObject()! as RenderBox;
532 533 534 535
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(50.0, 50.0)));

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

536
    box = key.currentContext!.findRenderObject()! as RenderBox;
537 538 539
    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
            AnimatedPositionedDirectional(
545 546 547 548 549
              start: 0.0,
              top: 100.0,
              end: 100.0, // 700.0 from the start
              height: 100.0,
              duration: const Duration(seconds: 2),
550
              child: Container(key: key),
551 552 553 554
            ),
          ],
        ),
      ),
555 556
    );

557
    box = key.currentContext!.findRenderObject()! as RenderBox;
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()! as RenderBox;
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()! as RenderBox;
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
            AnimatedPositionedDirectional(
582 583 584 585 586
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
587
              child: Container(key: key),
588 589 590 591 592 593
            ),
          ],
        ),
      ),
    );

594
    box = key.currentContext!.findRenderObject()! as RenderBox;
595 596 597 598
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

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

599
    box = key.currentContext!.findRenderObject()! as RenderBox;
600 601 602
    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
            AnimatedPositionedDirectional(
608 609 610 611 612
              start: 100.0,
              top: 100.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
613
              child: Container(key: key),
614 615 616 617 618 619
            ),
          ],
        ),
      ),
    );

620
    box = key.currentContext!.findRenderObject()! as RenderBox;
621 622 623 624
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

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

625
    box = key.currentContext!.findRenderObject()! as RenderBox;
626 627 628
    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
            AnimatedPositionedDirectional(
634 635 636 637 638
              start: 150.0,
              top: 150.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
639
              child: Container(key: key),
640 641 642 643 644 645
            ),
          ],
        ),
      ),
    );

646
    box = key.currentContext!.findRenderObject()! as RenderBox;
647 648 649 650
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(700.0, 100.0)));

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

651
    box = key.currentContext!.findRenderObject()! as RenderBox;
652 653 654 655
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(650.0, 150.0)));

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

656
    box = key.currentContext!.findRenderObject()! as RenderBox;
657 658 659 660
    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
            AnimatedPositionedDirectional(
671 672 673 674 675
              start: 0.0,
              top: 0.0,
              width: 100.0,
              height: 100.0,
              duration: const Duration(seconds: 2),
676
              child: Container(key: key),
677 678 679 680 681 682
            ),
          ],
        ),
      ),
    );

683
    box = key.currentContext!.findRenderObject()! as RenderBox;
684 685 686 687
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(750.0, 50.0)));

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

688
    box = key.currentContext!.findRenderObject()! as RenderBox;
689 690 691
    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
            AnimatedPositionedDirectional(
697 698 699 700 701
              start: 0.0,
              top: 100.0,
              end: 100.0, // 700.0 from the start
              height: 100.0,
              duration: const Duration(seconds: 2),
702
              child: Container(key: key),
703 704 705 706 707 708
            ),
          ],
        ),
      ),
    );

709
    box = key.currentContext!.findRenderObject()! as RenderBox;
710 711 712 713
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 50.0)));

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

714
    box = key.currentContext!.findRenderObject()! as RenderBox;
715 716 717 718
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 100.0)));

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

719
    box = key.currentContext!.findRenderObject()! as RenderBox;
720 721 722
    expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(450.0, 150.0)));
  });

Ian Hickson's avatar
Ian Hickson committed
723
}