
Now a RenderBox is considered hit if one of its children are hit or it itself decides that it's hit. In particular, empty space inside a flex won't be hit because none of the children are located there and a RenderFlex doesn't consider itself hittable. Fixes #53 Fixes #1221
155 lines
4.3 KiB
Dart
155 lines
4.3 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'widget_tester.dart';
|
|
|
|
void main() {
|
|
test('Transform origin', () {
|
|
testWidgets((WidgetTester tester) {
|
|
bool didReceiveTap = false;
|
|
tester.pumpWidget(
|
|
new Stack(<Widget>[
|
|
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, 50.0),
|
|
child: new GestureDetector(
|
|
onTap: () {
|
|
didReceiveTap = true;
|
|
},
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFF00FFFF)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
])
|
|
);
|
|
|
|
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 alignment', () {
|
|
testWidgets((WidgetTester tester) {
|
|
bool didReceiveTap = false;
|
|
tester.pumpWidget(
|
|
new Stack(<Widget>[
|
|
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;
|
|
},
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFF00FFFF)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
])
|
|
);
|
|
|
|
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(
|
|
new Stack(<Widget>[
|
|
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;
|
|
},
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFF00FFFF)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
])
|
|
);
|
|
|
|
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);
|
|
});
|
|
});
|
|
}
|