Flutter手势(粘贴即用 flutter 1.22.6)

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,

      ),

    );

  }

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容