GestureDetector是一个功能WIdget,可以识别出手指在屏幕的操作。 常见的识别操作有:
- onTap:单击
- onDoubleTap:双击
- onLongPress:长按
还有很多其他的操作,用到时再添加。
class _MyHomePageState extends State<MyHomePage> {
double imgWidth = 300;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: GestureDetector(
child: Image.asset("images/avatar.jpg",width: imgWidth,),
onTap: (){print('onTap单击');},
onDoubleTap: (){print('onDouble双击');},
onLongPress: (){print('onLongPress长按');},
),
),
);
}
}