Flutter教学

Flutter(32):Material组件之Chip

2020-10-04  本文已影响0人  starryxp

Flutter教学目录持续更新中

Github源代码持续更新中

1.Chip介绍

2.Chip属性

3.ActionChip属性

4.ChoiceChip属性

5.FilterChip属性

6.InputChip属性

7.Chip

这是一个最基础的Chip,功能也相对较少


1601714295(1).png
 _myChip() {
    return Chip(
      avatar: Icon(Icons.account_circle),
      label: Text('Chip'),
      labelStyle: TextStyle(
        fontSize: 14,
        color: Colors.black,
      ),
      labelPadding: EdgeInsets.all(10),
      deleteIcon: Icon(Icons.delete) /*Image.asset('images/scan.png')*/,
      onDeleted: () {
        ToastUtil.showToast('onDeleted');
      },
      deleteIconColor: Colors.red,
      deleteButtonTooltipMessage: '删除',
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      clipBehavior: Clip.antiAlias,
      backgroundColor: Colors.grey,
      padding: EdgeInsets.all(10),
      elevation: 10,
      shadowColor: Colors.amber,
    );
  }

8.ActionChip

这个比Chip多了点击事件,长安提示,还可以设置点击阴影,但是去掉了删除属性


未点击.png 点击时.png
 _myActionChip() {
    return ActionChip(
      avatar: Icon(Icons.account_circle),
      label: Text('ActionChip'),
      labelStyle: TextStyle(
        fontSize: 14,
        color: Colors.black,
      ),
      labelPadding: EdgeInsets.all(10),
      onPressed: () {
        ToastUtil.showToast('onPressed');
      },
      pressElevation: 20,
      tooltip: 'InputChip',
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      clipBehavior: Clip.antiAlias,
      backgroundColor: Colors.amber,
      padding: EdgeInsets.all(10),
      elevation: 10,
      shadowColor: Colors.amber,
    );
  }

9.ChoiceChip

在ActionChip基础上多了是否选中,取消了点击事件,跟长按事件


未选中.png 已选中.png
_myChoiceChip() {
    return ChoiceChip(
      avatar: Icon(Icons.account_circle),
      label: Text('ChoiceChip'),
      labelStyle: TextStyle(
        fontSize: 14,
        color: Colors.black,
      ),
      labelPadding: EdgeInsets.all(10),
      selected: _isSelected,
      onSelected: (isSelected) {
        setState(() {
          _isSelected = isSelected;
        });
      },
      pressElevation: 20,
      disabledColor: Colors.grey,
      selectedColor: Colors.blue,
      tooltip: 'InputChip',
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      clipBehavior: Clip.antiAlias,
      backgroundColor: Colors.amber,
      padding: EdgeInsets.all(10),
      elevation: 10,
      shadowColor: Colors.amber,
      selectedShadowColor: Colors.blue,
      avatarBorder: CircleBorder(),
    );
  }

10.FilterChip

在ChoiceChip多了checkMark等属性,选中时会在avatar位置出现一个✔


1601714876(1).png 1601714884(1).png
_myFilterChip() {
    return FilterChip(
      avatar: Icon(Icons.account_circle),
      label: Text('FilterChip'),
      labelStyle: TextStyle(
        fontSize: 14,
        color: Colors.black,
      ),
      labelPadding: EdgeInsets.all(10),
      selected: _isSelected,
      onSelected: (isSelected) {
        setState(() {
          _isSelected = isSelected;
        });
      },
      pressElevation: 20,
      disabledColor: Colors.grey,
      selectedColor: Colors.blue,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      clipBehavior: Clip.antiAlias,
      backgroundColor: Colors.amber,
      padding: EdgeInsets.all(10),
      elevation: 10,
      shadowColor: Colors.amber,
      selectedShadowColor: Colors.blue,
      checkmarkColor: Colors.red,
      showCheckmark: true,
      avatarBorder: CircleBorder(),
    );
  }

11.InputChip

这个相当于前面所有功能的聚合了,属性基本都有,但是有几个注意点

1601714910(1).png
_myInputChip() {
    return InputChip(
      avatar: Icon(Icons.account_circle),
      label: Text('InputChip'),
      labelStyle: TextStyle(
        fontSize: 14,
        color: Colors.black,
      ),
      labelPadding: EdgeInsets.all(10),
      selected: _isSelected,
      isEnabled: true,
      onSelected: (isSelected) {
        setState(() {
          _isSelected = isSelected;
        });
      },
      deleteIcon: Icon(Icons.delete),
      onDeleted: () {
        ToastUtil.showToast('onDeleted');
      },
      deleteIconColor: Colors.red,
      deleteButtonTooltipMessage: '删除',
      // onPressed: () {
      //   ToastUtil.showToast('onPressed');
      // },
      pressElevation: 20,
      disabledColor: Colors.grey,
      selectedColor: Colors.blue,
      tooltip: 'InputChip',
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      clipBehavior: Clip.antiAlias,
      backgroundColor: Colors.amber,
      padding: EdgeInsets.all(10),
      elevation: 10,
      shadowColor: Colors.amber,
      selectedShadowColor: Colors.blue,
      checkmarkColor: Colors.red,
      showCheckmark: true,
      avatarBorder: CircleBorder(),
    );
  }

下一节:Material组件之ListTile、RefreshIndicator、ListView、Divider

Flutter(33):Material组件之ListTile、RefreshIndicator、ListView、Divider

Flutter教学目录持续更新中

Github源代码持续更新中

上一篇下一篇

猜你喜欢

热点阅读