transform_test.dart 4.51 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4
// 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.

5
import 'package:flutter/widgets.dart';
6 7
import 'package:test/test.dart';

Adam Barth's avatar
Adam Barth committed
8
import 'widget_tester.dart';
9 10 11

void main() {
  test('Transform origin', () {
12 13 14
    testWidgets((WidgetTester tester) {
      bool didReceiveTap = false;
      tester.pumpWidget(
15
        new Stack(<Widget>[
16 17 18 19 20 21 22 23 24
          new Positioned(
            top: 100.0,
            left: 100.0,
            child: new Container(
              width: 100.0,
              height: 100.0,
              decoration: new BoxDecoration(
                backgroundColor: new Color(0xFF0000FF)
              )
25
            )
26 27 28 29 30 31 32 33 34 35 36 37 38 39
          ),
          new Positioned(
            top: 100.0,
            left: 100.0,
            child: new Container(
              width: 100.0,
              height: 100.0,
              child: new Transform(
                transform: new Matrix4.identity().scale(0.5, 0.5),
                origin: new Offset(100.0, 50.0),
                child: new GestureDetector(
                  onTap: () {
                    didReceiveTap = true;
                  },
Adam Barth's avatar
Adam Barth committed
40 41 42 43 44
                  child: new Container(
                    decoration: new BoxDecoration(
                      backgroundColor: new Color(0xFF00FFFF)
                    )
                  )
45
                )
46 47 48
              )
            )
          )
49 50
        ])
      );
51

52 53 54 55 56 57
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(110.0, 110.0));
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(190.0, 150.0));
      expect(didReceiveTap, isTrue);
    });
58
  });
Hixie's avatar
Hixie committed
59 60 61 62 63

  test('Transform alignment', () {
    testWidgets((WidgetTester tester) {
      bool didReceiveTap = false;
      tester.pumpWidget(
64
        new Stack(<Widget>[
Hixie's avatar
Hixie committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
          new Positioned(
            top: 100.0,
            left: 100.0,
            child: new Container(
              width: 100.0,
              height: 100.0,
              decoration: new BoxDecoration(
                backgroundColor: new Color(0xFF0000FF)
              )
            )
          ),
          new Positioned(
            top: 100.0,
            left: 100.0,
            child: new Container(
              width: 100.0,
              height: 100.0,
              child: new Transform(
                transform: new Matrix4.identity().scale(0.5, 0.5),
                alignment: new FractionalOffset(1.0, 0.5),
                child: new GestureDetector(
                  onTap: () {
                    didReceiveTap = true;
                  },
Adam Barth's avatar
Adam Barth committed
89 90 91 92 93
                  child: new Container(
                    decoration: new BoxDecoration(
                      backgroundColor: new Color(0xFF00FFFF)
                    )
                  )
Hixie's avatar
Hixie committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
                )
              )
            )
          )
        ])
      );

      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(110.0, 110.0));
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(190.0, 150.0));
      expect(didReceiveTap, isTrue);
    });
  });

  test('Transform offset + alignment', () {
    testWidgets((WidgetTester tester) {
      bool didReceiveTap = false;
      tester.pumpWidget(
113
        new Stack(<Widget>[
Hixie's avatar
Hixie committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
          new Positioned(
            top: 100.0,
            left: 100.0,
            child: new Container(
              width: 100.0,
              height: 100.0,
              decoration: new BoxDecoration(
                backgroundColor: new Color(0xFF0000FF)
              )
            )
          ),
          new Positioned(
            top: 100.0,
            left: 100.0,
            child: new Container(
              width: 100.0,
              height: 100.0,
              child: new Transform(
                transform: new Matrix4.identity().scale(0.5, 0.5),
                origin: new Offset(100.0, 0.0),
                alignment: new FractionalOffset(0.0, 0.5),
                child: new GestureDetector(
                  onTap: () {
                    didReceiveTap = true;
                  },
Adam Barth's avatar
Adam Barth committed
139 140 141 142 143
                  child: new Container(
                    decoration: new BoxDecoration(
                      backgroundColor: new Color(0xFF00FFFF)
                    )
                  )
Hixie's avatar
Hixie committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157
                )
              )
            )
          )
        ])
      );

      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(110.0, 110.0));
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(190.0, 150.0));
      expect(didReceiveTap, isTrue);
    });
  });
158
}