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

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

看效果

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


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

查看所有标签

猜你喜欢:

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

Learning JavaScript

Learning JavaScript

Shelley Powers / Oreilly & Associates Inc / 2006-10-17 / $29.99

As web browsers have become more capable and standards compliant, JavaScript has grown in prominence. JavaScript lets designers add sparkle and life to web pages, while more complex JavaScript has led......一起来看看 《Learning JavaScript》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

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

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具