transform_test.dart 25.3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hixie's avatar
Hixie 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 7 8
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])

9
import 'dart:math' as math;
10
import 'dart:ui' as ui;
11

12
import 'package:flutter/rendering.dart';
13
import 'package:flutter/widgets.dart';
14
import 'package:flutter_test/flutter_test.dart';
15
import 'package:vector_math/vector_math_64.dart';
16 17

void main() {
18
  testWidgets('Transform origin', (WidgetTester tester) async {
19
    bool didReceiveTap = false;
20
    await tester.pumpWidget(
21
      Directionality(
22
        textDirection: TextDirection.ltr,
23
        child: Stack(
24
          children: <Widget>[
25
            Positioned(
26 27
              top: 100.0,
              left: 100.0,
28
              child: Container(
29 30 31 32
                width: 100.0,
                height: 100.0,
                color: const Color(0xFF0000FF),
              ),
33
            ),
34
            Positioned(
35 36
              top: 100.0,
              left: 100.0,
37
              child: SizedBox(
38 39
                width: 100.0,
                height: 100.0,
40 41
                child: Transform(
                  transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0),
42
                  origin: const Offset(100.0, 50.0),
43
                  child: GestureDetector(
44 45 46
                    onTap: () {
                      didReceiveTap = true;
                    },
47
                    child: Container(
48 49
                      color: const Color(0xFF00FFFF),
                    ),
50 51 52 53
                  ),
                ),
              ),
            ),
54 55
          ],
        ),
56
      ),
57
    );
58

59
    expect(didReceiveTap, isFalse);
60
    await tester.tapAt(const Offset(110.0, 110.0));
61
    expect(didReceiveTap, isFalse);
62
    await tester.tapAt(const Offset(190.0, 150.0));
63
    expect(didReceiveTap, isTrue);
64
  });
Hixie's avatar
Hixie committed
65

66
  testWidgets('Transform alignment', (WidgetTester tester) async {
67
    bool didReceiveTap = false;
68
    await tester.pumpWidget(
69
      Directionality(
70
        textDirection: TextDirection.ltr,
71
        child: Stack(
72
          children: <Widget>[
73
            Positioned(
74 75
              top: 100.0,
              left: 100.0,
76
              child: Container(
77 78 79 80
                width: 100.0,
                height: 100.0,
                color: const Color(0xFF0000FF),
              ),
81
            ),
82
            Positioned(
83 84
              top: 100.0,
              left: 100.0,
85
              child: SizedBox(
86 87
                width: 100.0,
                height: 100.0,
88 89
                child: Transform(
                  transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0),
90
                  alignment: Alignment.centerRight,
91
                  child: GestureDetector(
92 93 94
                    onTap: () {
                      didReceiveTap = true;
                    },
95
                    child: Container(
96 97
                      color: const Color(0xFF00FFFF),
                    ),
98 99 100 101
                  ),
                ),
              ),
            ),
102 103
          ],
        ),
104
      ),
105
    );
Hixie's avatar
Hixie committed
106

107
    expect(didReceiveTap, isFalse);
108
    await tester.tapAt(const Offset(110.0, 110.0));
109
    expect(didReceiveTap, isFalse);
110
    await tester.tapAt(const Offset(190.0, 150.0));
111
    expect(didReceiveTap, isTrue);
Hixie's avatar
Hixie committed
112 113
  });

114 115 116 117
  testWidgets('Transform AlignmentDirectional alignment', (WidgetTester tester) async {
    bool didReceiveTap = false;

    Widget buildFrame(TextDirection textDirection, AlignmentGeometry alignment) {
118
      return Directionality(
119
        textDirection: textDirection,
120
        child: Stack(
121
          children: <Widget>[
122
            Positioned(
123 124
              top: 100.0,
              left: 100.0,
125
              child: Container(
126 127 128 129 130
                width: 100.0,
                height: 100.0,
                color: const Color(0xFF0000FF),
              ),
            ),
131
            Positioned(
132 133
              top: 100.0,
              left: 100.0,
134
              child: SizedBox(
135 136
                width: 100.0,
                height: 100.0,
137 138
                child: Transform(
                  transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0),
139
                  alignment: alignment,
140
                  child: GestureDetector(
141 142 143
                    onTap: () {
                      didReceiveTap = true;
                    },
144
                    child: Container(
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
                      color: const Color(0xFF00FFFF),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    }

    await tester.pumpWidget(buildFrame(TextDirection.ltr, AlignmentDirectional.centerEnd));
    didReceiveTap = false;
    await tester.tapAt(const Offset(110.0, 110.0));
    expect(didReceiveTap, isFalse);
    await tester.tapAt(const Offset(190.0, 150.0));
    expect(didReceiveTap, isTrue);

    await tester.pumpWidget(buildFrame(TextDirection.rtl, AlignmentDirectional.centerStart));
    didReceiveTap = false;
    await tester.tapAt(const Offset(110.0, 110.0));
    expect(didReceiveTap, isFalse);
    await tester.tapAt(const Offset(190.0, 150.0));
    expect(didReceiveTap, isTrue);

    await tester.pumpWidget(buildFrame(TextDirection.ltr, AlignmentDirectional.centerStart));
    didReceiveTap = false;
    await tester.tapAt(const Offset(190.0, 150.0));
    expect(didReceiveTap, isFalse);
    await tester.tapAt(const Offset(110.0, 150.0));
    expect(didReceiveTap, isTrue);

    await tester.pumpWidget(buildFrame(TextDirection.rtl, AlignmentDirectional.centerEnd));
    didReceiveTap = false;
    await tester.tapAt(const Offset(190.0, 150.0));
    expect(didReceiveTap, isFalse);
    await tester.tapAt(const Offset(110.0, 150.0));
    expect(didReceiveTap, isTrue);
  });

185
  testWidgets('Transform offset + alignment', (WidgetTester tester) async {
186
    bool didReceiveTap = false;
187
    await tester.pumpWidget(
188
      Directionality(
189
        textDirection: TextDirection.ltr,
190
        child: Stack(
191
          children: <Widget>[
192
            Positioned(
193 194
              top: 100.0,
              left: 100.0,
195
              child: Container(
196 197 198 199 200
                width: 100.0,
                height: 100.0,
                color: const Color(0xFF0000FF),
              ),
            ),
201
            Positioned(
202 203
              top: 100.0,
              left: 100.0,
204
              child: SizedBox(
205 206
                width: 100.0,
                height: 100.0,
207 208
                child: Transform(
                  transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0),
209
                  origin: const Offset(100.0, 0.0),
210
                  alignment: Alignment.centerLeft,
211
                  child: GestureDetector(
212 213 214
                    onTap: () {
                      didReceiveTap = true;
                    },
215
                    child: Container(
216 217 218
                      color: const Color(0xFF00FFFF),
                    ),
                  ),
219 220 221
                ),
              ),
            ),
222
          ],
223
        ),
224 225
      ),
    );
Hixie's avatar
Hixie committed
226

227
    expect(didReceiveTap, isFalse);
228
    await tester.tapAt(const Offset(110.0, 110.0));
229
    expect(didReceiveTap, isFalse);
230
    await tester.tapAt(const Offset(190.0, 150.0));
231
    expect(didReceiveTap, isTrue);
Hixie's avatar
Hixie committed
232
  });
233 234 235

  testWidgets('Composited transform offset', (WidgetTester tester) async {
    await tester.pumpWidget(
236 237
      Center(
        child: SizedBox(
238 239
          width: 400.0,
          height: 300.0,
240 241 242
          child: ClipRect(
            child: Transform(
              transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0),
243
              child: RepaintBoundary(
244
                child: Container(
245
                  color: const Color(0xFF00FF00),
246 247 248 249 250 251 252 253
                ),
              ),
            ),
          ),
        ),
      ),
    );

254
    final List<Layer> layers = tester.layers
255 256 257
      ..retainWhere((Layer layer) => layer is TransformLayer);
    expect(layers.length, 2);
    // The first transform is from the render view.
258
    final TransformLayer layer = layers[1] as TransformLayer;
259
    final Matrix4 transform = layer.transform!;
260
    expect(transform.getTranslation(), equals(Vector3(100.0, 75.0, 0.0)));
261
  });
262 263 264

  testWidgets('Transform.rotate', (WidgetTester tester) async {
    await tester.pumpWidget(
265
      Transform.rotate(
266
        angle: math.pi / 2.0,
267
        child: RepaintBoundary(child: Container()),
268 269 270 271 272 273 274
      ),
    );

    final List<Layer> layers = tester.layers
      ..retainWhere((Layer layer) => layer is TransformLayer);
    expect(layers.length, 2);
    // The first transform is from the render view.
275
    final TransformLayer layer = layers[1] as TransformLayer;
276
    final Matrix4 transform = layer.transform!;
277 278 279 280 281 282 283
    expect(transform.storage, <dynamic>[
      moreOrLessEquals(0.0), 1.0, 0.0, 0.0,
      -1.0, moreOrLessEquals(0.0), 0.0, 0.0,
      0.0, 0.0, 1.0, 0.0,
      700.0, -100.0, 0.0, 1.0,
    ]);
  });
284 285 286

  testWidgets('applyPaintTransform of Transform in Padding', (WidgetTester tester) async {
    await tester.pumpWidget(
287
      Padding(
288 289 290 291 292 293
        padding: const EdgeInsets.only(
          left: 30.0,
          top: 20.0,
          right: 50.0,
          bottom: 70.0,
        ),
294 295
        child: Transform(
          transform: Matrix4.diagonal3Values(2.0, 2.0, 2.0),
296 297 298 299 300 301
          child: const Placeholder(),
        ),
      ),
    );
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(30.0, 20.0));
  });
302 303 304

  testWidgets('Transform.translate', (WidgetTester tester) async {
    await tester.pumpWidget(
305
      Transform.translate(
306
        offset: const Offset(100.0, 50.0),
307
        child: RepaintBoundary(child: Container()),
308 309 310 311 312 313 314 315 316 317 318 319
      ),
    );

    // This should not cause a transform layer to be inserted.
    final List<Layer> layers = tester.layers
      ..retainWhere((Layer layer) => layer is TransformLayer);
    expect(layers.length, 1); // only the render view
    expect(tester.getTopLeft(find.byType(Container)), const Offset(100.0, 50.0));
  });

  testWidgets('Transform.scale', (WidgetTester tester) async {
    await tester.pumpWidget(
320
      Transform.scale(
321
        scale: 2.0,
322
        child: RepaintBoundary(child: Container()),
323 324 325 326 327 328 329
      ),
    );

    final List<Layer> layers = tester.layers
      ..retainWhere((Layer layer) => layer is TransformLayer);
    expect(layers.length, 2);
    // The first transform is from the render view.
330
    final TransformLayer layer = layers[1] as TransformLayer;
331
    final Matrix4 transform = layer.transform!;
332 333 334 335 336 337 338 339
    expect(transform.storage, <dynamic>[
      // These are column-major, not row-major.
      2.0, 0.0, 0.0, 0.0,
      0.0, 2.0, 0.0, 0.0,
      0.0, 0.0, 1.0, 0.0,
      -400.0, -300.0, 0.0, 1.0, // it's 1600x1200, centered in an 800x600 square
    ]);
  });
Emmanuel Garcia's avatar
Emmanuel Garcia committed
340

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 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
  testWidgets('Transform with nan value short-circuits rendering', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform(
        transform: Matrix4.identity()
          ..storage[0] = double.nan,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(1));
  });

  testWidgets('Transform with inf value short-circuits rendering', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform(
        transform: Matrix4.identity()
          ..storage[0] = double.infinity,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(1));
  });

  testWidgets('Transform with -inf value short-circuits rendering', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform(
        transform: Matrix4.identity()
          ..storage[0] = double.negativeInfinity,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(1));
  });

  testWidgets('Transform.rotate does not remove layers due to singular short-circuit', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi / 2,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(3));
  });

  testWidgets('Transform.rotate creates nice rotation matrices for 0, 90, 180, 270 degrees', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi / 2,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers[1], isA<TransformLayer>()
      .having((TransformLayer layer) => layer.transform, 'transform', equals(Matrix4.fromList(<double>[
        0.0, -1.0, 0.0, 700.0,
        1.0, 0.0, 0.0, -100.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0,
      ])..transpose()))
    );

    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers[1], isA<TransformLayer>()
      .having((TransformLayer layer) => layer.transform, 'transform', equals(Matrix4.fromList(<double>[
       -1.0, 0.0, 0.0, 800.0,
        0.0, -1.0, 0.0, 600.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0,
      ])..transpose()))
    );

    await tester.pumpWidget(
      Transform.rotate(
        angle: 3 * math.pi / 2,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers[1], isA<TransformLayer>()
      .having((TransformLayer layer) => layer.transform, 'transform', equals(Matrix4.fromList(<double>[
        0.0, 1.0, 0.0, 100.0,
       -1.0, 0.0, 0.0, 700.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0,
      ])..transpose()))
    );

    await tester.pumpWidget(
      Transform.rotate(
        angle: 0,
        child: RepaintBoundary(child: Container()),
      ),
    );

    // No transform layer created
    expect(tester.layers[1], isA<OffsetLayer>());
    expect(tester.layers, hasLength(2));
  });

  testWidgets('Transform.scale with 0.0 does not paint child layers', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform.scale(
        scale: 0.0,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(1)); // root transform layer

    await tester.pumpWidget(
      Transform.scale(
        scaleX: 0.0,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(1));

    await tester.pumpWidget(
      Transform.scale(
        scaleY: 0.0,
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(1));

    await tester.pumpWidget(
      Transform.scale(
        scale: 0.01, // small but non-zero
        child: RepaintBoundary(child: Container()),
      ),
    );

    expect(tester.layers, hasLength(3));
  });


Emmanuel Garcia's avatar
Emmanuel Garcia committed
488
  testWidgets('Translated child into translated box - hit test', (WidgetTester tester) async {
489
    final GlobalKey key1 = GlobalKey();
490
    bool pointerDown = false;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
491
    await tester.pumpWidget(
492
      Transform.translate(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
493
        offset: const Offset(100.0, 50.0),
494
        child: Transform.translate(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
495
          offset: const Offset(1000.0, 1000.0),
496
          child: Listener(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
497
            onPointerDown: (PointerDownEvent event) {
498
              pointerDown = true;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
499
            },
500
            child: Container(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
501 502
              key: key1,
              color: const Color(0xFF000000),
503 504 505
            ),
          ),
        ),
Emmanuel Garcia's avatar
Emmanuel Garcia committed
506 507
      ),
    );
508
    expect(pointerDown, isFalse);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
509
    await tester.tap(find.byKey(key1));
510
    expect(pointerDown, isTrue);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
511
  });
512

513
  Widget generateTransform(bool needsCompositing, double angle) {
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
    final Widget customPaint = CustomPaint(painter: TestRectPainter());
    return Transform(
      transform: MatrixUtils.createCylindricalProjectionTransform(
        radius: 100,
        angle: angle,
        perspective: 0.003,
      ),
      // A RepaintBoundary child forces the Transform to needsCompositing
      child: needsCompositing ? RepaintBoundary(child: customPaint) : customPaint,
    );
  }

  testWidgets(
    '3D transform renders the same with or without needsCompositing',
    (WidgetTester tester) async {
      for (double angle = 0; angle <= math.pi/4; angle += 0.01) {
530
        await tester.pumpWidget(RepaintBoundary(child: generateTransform(true, angle)));
531 532
        final RenderBox renderBox = tester.binding.renderView.child!;
        final OffsetLayer layer = renderBox.debugLayer! as OffsetLayer;
533 534
        final ui.Image imageWithCompositing = await layer.toImage(renderBox.paintBounds);

535
        await tester.pumpWidget(RepaintBoundary(child: generateTransform(false, angle)));
536 537 538
        await expectLater(find.byType(RepaintBoundary).first, matchesReferenceImage(imageWithCompositing));
      }
    },
539
    skip: isBrowser, // due to https://github.com/flutter/flutter/issues/49857
540
  );
541

542 543 544 545 546
  List<double> extractMatrix(ui.ImageFilter? filter) {
    final List<String> numbers = filter.toString().split('[').last.split(']').first.split(',');
    return numbers.map<double>((String str) => double.parse(str.trim())).toList();
  }

547 548 549 550 551
  testWidgets('Transform.translate with FilterQuality produces filter layer', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform.translate(
        offset: const Offset(25.0, 25.0),
        filterQuality: FilterQuality.low,
552
        child: const SizedBox(width: 100, height: 100),
553 554 555
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
556 557 558 559 560
    final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
    expect(extractMatrix(layer.imageFilter), <double>[
      1.0, 0.0, 0.0, 0.0,
      0.0, 1.0, 0.0, 0.0,
      0.0, 0.0, 1.0, 0.0,
561 562
      25.0, 25.0, 0.0, 1.0,
    ]);
563 564 565 566 567 568 569
  });

  testWidgets('Transform.scale with FilterQuality produces filter layer', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform.scale(
        scale: 3.14159,
        filterQuality: FilterQuality.low,
570
        child: const SizedBox(width: 100, height: 100),
571 572 573
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
574 575 576 577 578
    final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
    expect(extractMatrix(layer.imageFilter), <double>[
      3.14159, 0.0, 0.0, 0.0,
      0.0, 3.14159, 0.0, 0.0,
      0.0, 0.0, 1.0, 0.0,
579 580
      -856.636, -642.477, 0.0, 1.0,
    ]);
581 582 583 584 585 586 587
  });

  testWidgets('Transform.rotate with FilterQuality produces filter layer', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi / 4,
        filterQuality: FilterQuality.low,
588
        child: const SizedBox(width: 100, height: 100),
589 590 591
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
592 593 594 595 596
    final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
    expect(extractMatrix(layer.imageFilter), <dynamic>[
      moreOrLessEquals(0.7071067811865476), moreOrLessEquals(0.7071067811865475), 0.0, 0.0,
      moreOrLessEquals(-0.7071067811865475), moreOrLessEquals(0.7071067811865476), 0.0, 0.0,
      0.0, 0.0, 1.0, 0.0,
597 598
      moreOrLessEquals(329.28932188134524), moreOrLessEquals(-194.97474683058329), 0.0, 1.0,
    ]);
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
  });

  testWidgets('Offset Transform.rotate with FilterQuality produces filter layer', (WidgetTester tester) async {
    await tester.pumpWidget(
      SizedBox(width: 400, height: 400,
        child: Center(
          child: Transform.rotate(
            angle: math.pi / 4,
            filterQuality: FilterQuality.low,
            child: const SizedBox(width: 100, height: 100),
          ),
        ),
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
    final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
    expect(extractMatrix(layer.imageFilter), <dynamic>[
      moreOrLessEquals(0.7071067811865476), moreOrLessEquals(0.7071067811865475), 0.0, 0.0,
      moreOrLessEquals(-0.7071067811865475), moreOrLessEquals(0.7071067811865476), 0.0, 0.0,
      0.0, 0.0, 1.0, 0.0,
619 620
      moreOrLessEquals(329.28932188134524), moreOrLessEquals(-194.97474683058329), 0.0, 1.0,
    ]);
621 622 623 624 625 626 627
  });

  testWidgets('Transform layers update to match child and filterQuality', (WidgetTester tester) async {
    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi / 4,
        filterQuality: FilterQuality.low,
628
        child: const SizedBox(width: 100, height: 100),
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>(), hasLength(1));

    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi / 4,
        child: const SizedBox(width: 100, height: 100),
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>(), isEmpty);

    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi / 4,
        filterQuality: FilterQuality.low,
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>(), isEmpty);

    await tester.pumpWidget(
      Transform.rotate(
        angle: math.pi / 4,
        filterQuality: FilterQuality.low,
653
        child: const SizedBox(width: 100, height: 100),
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
      ),
    );
    expect(tester.layers.whereType<ImageFilterLayer>(), hasLength(1));
  });

  testWidgets('Transform layers with filterQuality golden', (WidgetTester tester) async {
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView.count(
          crossAxisCount: 3,
          children: <Widget>[
            Transform.rotate(
              angle: math.pi / 6,
              child: Center(child: Container(width: 100, height: 20, color: const Color(0xffffff00))),
            ),
            Transform.scale(
              scale: 1.5,
              child: Center(child: Container(width: 100, height: 20, color: const Color(0xffffff00))),
            ),
            Transform.translate(
              offset: const Offset(20.0, 60.0),
              child: Center(child: Container(width: 100, height: 20, color: const Color(0xffffff00))),
            ),
            Transform.rotate(
              angle: math.pi / 6,
              filterQuality: FilterQuality.low,
681
              child: Center(child: Container(width: 100, height: 20, color: const Color(0xff00ff00))),
682 683 684 685
            ),
            Transform.scale(
              scale: 1.5,
              filterQuality: FilterQuality.low,
686
              child: Center(child: Container(width: 100, height: 20, color: const Color(0xff00ff00))),
687 688 689 690
            ),
            Transform.translate(
              offset: const Offset(20.0, 60.0),
              filterQuality: FilterQuality.low,
691
              child: Center(child: Container(width: 100, height: 20, color: const Color(0xff00ff00))),
692 693 694 695 696 697 698 699 700 701
            ),
          ],
        ),
      ),
    );
    await expectLater(
      find.byType(GridView),
      matchesGoldenFile('transform_golden.BitmapRotate.png'),
    );
  });
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736

  testWidgets("Transform.scale() does not accept all three 'scale', 'scaleX' and 'scaleY' parameters to be non-null", (WidgetTester tester) async {
    await expectLater(() {
      tester.pumpWidget(Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: Transform.scale(
              scale: 1.0,
              scaleX: 1.0,
              scaleY: 1.0,
              child: const SizedBox(
                height: 100,
                width: 100,
              ),
            ),
          )));
    }, throwsAssertionError);
  });

  testWidgets("Transform.scale() needs at least one of 'scale', 'scaleX' and 'scaleY' to be non-null, otherwise throws AssertionError", (WidgetTester tester) async {
    await expectLater(() {
      tester.pumpWidget(Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: Transform.scale(
              child: const SizedBox(
                height: 100,
                width: 100,
              ),
            ),
          )));
    }, throwsAssertionError);
  });

  testWidgets("Transform.scale() scales widget uniformly with 'scale' parameter", (WidgetTester tester) async {
737 738 739
    const double scale = 1.5;
    const double height = 100;
    const double width = 150;
740 741 742 743 744 745 746
    await tester.pumpWidget(Directionality(
        textDirection: TextDirection.ltr,
        child: SizedBox(
          height: 400,
          width: 400,
          child: Center(
            child: Transform.scale(
747
              scale: scale,
748
              child: Container(
749 750
                height: height,
                width: width,
751 752 753 754 755 756
                decoration: const BoxDecoration(),
              ),
            ),
          ),
        )));

757
    const Size target = Size(width * scale, height * scale);
758

759
    expect(tester.getBottomRight(find.byType(Container)), target.bottomRight(tester.getTopLeft(find.byType(Container))));
760 761 762
  });

  testWidgets("Transform.scale() scales widget according to 'scaleX' and 'scaleY'", (WidgetTester tester) async {
763 764 765 766
    const double scaleX = 1.5;
    const double scaleY = 1.2;
    const double height = 100;
    const double width = 150;
767 768 769 770 771 772 773
    await tester.pumpWidget(Directionality(
        textDirection: TextDirection.ltr,
        child: SizedBox(
          height: 400,
          width: 400,
          child: Center(
            child: Transform.scale(
774 775
              scaleX: scaleX,
              scaleY: scaleY,
776
              child: Container(
777 778
                height: height,
                width: width,
779 780 781 782 783 784
                decoration: const BoxDecoration(),
              ),
            ),
          ),
        )));

785
    const Size target = Size(width * scaleX, height * scaleY);
786

787
    expect(tester.getBottomRight(find.byType(Container)), target.bottomRight(tester.getTopLeft(find.byType(Container))));
788
  });
789 790 791 792 793 794 795 796 797 798 799 800
}

class TestRectPainter extends CustomPainter {
  @override
  void paint(ui.Canvas canvas, ui.Size size) {
    canvas.drawRect(
      const Offset(200, 200) & const Size(10, 10),
      Paint()..color = const Color(0xFFFF0000),
    );
  }
  @override
  bool shouldRepaint(CustomPainter oldDelegate) => true;
801
}