import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyAppextends StatelessWidget {
// This widget is the root of your application.
@override
Widgetbuild(BuildContext context) {
return MaterialApp(
title:'Flutter Demo',
theme:ThemeData(
primarySwatch: Colors.blue, splashColor: Colors.transparent),
home:HYHomePage(),
);
}
}
class HYHomePageextends StatelessWidget {
@override
Widgetbuild(BuildContext context) {
return Scaffold(
appBar:AppBar(
title:Text("列表测试"),
),
body:GestureDemo(),
// Center(
// child: Stack(
// alignment: Alignment.center,
// children: [
// GestureDetector(
// onTapDown: (details) {
// print("outer click");
// },
// child: Container(
// width: 200,
// height: 200,
// color: Colors.yellow,
// alignment: Alignment.center,
// ),
// ),
// IgnorePointer(
// child: GestureDetector(
// onTapDown: (details) {
// print("inner click");
// },
// child: Container(
// width: 100,
// height: 100,
// color: Colors.red,
// ),
// ),
// )
// ],
// ),
// ),
);
}
}
class GestureDemoextends StatelessWidget {
const GestureDemo({
Key key,
}) :super(key: key);
@override
Widgetbuild(BuildContext context) {
return Center(
child:GestureDetector(
onTapDown: (details) {
print("手指按下");
print(details.globalPosition);
print(details.localPosition);
},
onTapUp: (details) {
print("手指抬起");
},
onTapCancel: () {
print("手势取消");
},
onTap: () {
print("手势点击");
},
onDoubleTap: () {
print("手指双击");
},
onLongPress: () {
print("长按手势");
},
onPanUpdate: (value){
print('当前我在滑动$value');
},
child:Container(
width:200,
height:200,
color: Colors.orange,
),
),
);
}
}
class ListenerDemoextends StatelessWidget {
const ListenerDemo({
Key key,
}) :super(key: key);
@override
Widgetbuild(BuildContext context) {
return Listener(
onPointerDown: (event) {
print("指针按下:$event");
print(event.position);
print(event.localPosition);
},
onPointerMove: (event) {
// print("指针移动:$event");
},
onPointerUp: (event) {
// print("指针抬起:$event");
},
child:Container(
width:200,
height:200,
color: Colors.red,
),
);
}
}