美文网首页
flutter 手势处理GestureDetector

flutter 手势处理GestureDetector

作者: 喜剧收尾_XWX | 来源:发表于2020-08-17 11:39 被阅读0次
import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
    title: "手势处理demo",
    home: new MyPage(),
  ));
}

class MyButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new GestureDetector(
      onTap: () {
        //底部消息揭
        final snackBar = new SnackBar(content: new Text("你已经按下"));
        Scaffold.of(context).showSnackBar(snackBar);

        print("点击屏幕");
      },

      //添加容器
      child: Container(
        padding: EdgeInsets.all(12.0),
        decoration: BoxDecoration(
            color: Theme.of(context).buttonColor,
            borderRadius: BorderRadius.circular(10.0)),
        child: Text('测试按钮'),
      ),
    );
  }
}

class MyPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: AppBar(
        title: Text('按下demo处理'),
      ),
      body: new Center(
        child: MyButton(),
      ),
    );
  }
}

相关文章

网友评论

      本文标题:flutter 手势处理GestureDetector

      本文链接:https://www.haomeiwen.com/subject/eyiydktx.html