Flutter

Flutter Widget - 手势处理(GestureDet

2018-07-06  本文已影响24人  ChenME
// 调用自定义的 Button 
Widget renderBody(BuildContext context) {
  return new Center(
    child: new MyButton(),
  );
}

class MyButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      onLongPress: null,  // 长按事件
      onTap: () {  // 单击事件
        Scaffold.of(context).showBottomSheet((BuildContext context) {
          return new Container(
            color: Color(0xffff639b),
            width: double.infinity,
            height: 100.0,
            child: new Center(
              child: Text('I\'m Bottom Sheet'),
            ),
          );
        });
      },
      onDoubleTap: () {  // 双击事件
        Scaffold.of(context).showSnackBar(new SnackBar(content: new Text('I\'m Snack Bar')));
      },
      child: new Container(
        padding: new EdgeInsets.all(12.0),
        child: new Text('Custom Button'),
      ),
    );
  }
}
child
onTapDown
onTapUp
onTap
onTapCancel
onDoubleTap
onLongPress
onVerticalDragDown
onVerticalDragStart
onVerticalDragUpdate
onVerticalDragEnd
onVerticalDragCancel
onHorizontalDragDown
onHorizontalDragStart
onHorizontalDragUpdate
onHorizontalDragEnd
onHorizontalDragCancel
onPanDown
onPanStart
onPanUpdate
onPanEnd
onPanCancel
onScaleStart
onScaleUpdate
onScaleEnd
上一篇下一篇

猜你喜欢

热点阅读