flutter 自定义带水波纹和点击态的cell

栏目: Android · 发布时间: 6年前

看效果

flutter 自定义带水波纹和点击态的cell

代码:

class _CListTile extends StatefulWidget {
  _CListTile(
      {Key key,
      this.text,
      this.textColor: Colors.black,
      this.textHighLightColor: const Color(0xff25C78A),
      this.leadingIconPath,
      this.leadingHighLightIconPath,
      @required this.onTab})
      : super(key: key);

  final Function onTab;
  final String text;
  final Color textColor;
  final Color textHighLightColor;
  final String leadingIconPath;
  final String leadingHighLightIconPath;

  _CListTileState createState() => _CListTileState();
}

class _CListTileState extends State<_CListTile> {
  bool _highlight = false;

  void _handleTapDown(TapDownDetails details) {
    setState(() {
      _highlight = true;
    });
  }

  void _handleTapUp(TapUpDetails details) {
    setState(() {
      _highlight = false;
    });
  }

  void _handleTapCancel() {
    setState(() {
      _highlight = false;
    });
  }

  void _handleTap() {
    widget.onTab();
  }

  Widget build(BuildContext context) {
    return GestureDetector(
      onTapDown: _handleTapDown,
      onTapUp: _handleTapUp,
      onTap: _handleTap,
      onTapCancel: _handleTapCancel,
      child: Container(
        height: 52,
        child: Material(
          child: InkWell(
            onTap: (){
              if(widget.onTab != null) {
                widget.onTab();
              }
            },
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Padding(padding: EdgeInsets.only(left: 16)),
                _highlight
                    ? Image.asset(widget.leadingHighLightIconPath, width: 25)
                    : Image.asset(widget.leadingIconPath, width: 25),
                Padding(padding: EdgeInsets.only(left: 15)),
                Text(widget.text,
                    style: TextStyle(
                        fontSize: 16.0,
                        fontWeight: FontWeight.w600,
                        color: _highlight
                            ? widget.textHighLightColor
                            : widget.textColor)),
              ],
            ),
          ),
        )
      ),
    );
  }
}

使用的地方

_CListTile(
            text: "test title",
            leadingIconPath: "images/test.png",
            leadingHighLightIconPath: "images/test1.png",
            onTab: () {
              print("test");
            }),

热度: 16


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

API Design for C++

API Design for C++

Martin Reddy / Morgan Kaufmann / 2011-2-18 / USD 59.95

The design of application programming interfaces can affect the behavior, capabilities, stability, and ease of use of end-user applications. With this book, you will learn how to design a good API for......一起来看看 《API Design for C++》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具