一、Chip

Chip:标签,一个Material widget。 它可以将一个复杂内容实体展现在一个小块中,如联系人。

Chip 的定义

使用场景:事物的属性或标签,历史搜索记录等。

  1. const Chip({
  2. Key key,
  3. this.avatar,//标签左侧的Widget
  4. @required this.label,
  5. this.labelStyle,
  6. this.labelPadding,
  7. this.deleteIcon,//删除图标,要与删除回调一起使用
  8. this.onDeleted,//删除回调
  9. this.deleteIconColor,
  10. this.deleteButtonTooltipMessage,
  11. this.shape,//形状
  12. this.clipBehavior = Clip.none,
  13. this.backgroundColor,
  14. this.padding,
  15. this.materialTapTargetSize,
  16. this.elevation,//阴影
  17. })

ActionChip

ActionChip 多了一个onPressed事件回调,还多了一个pressElevation 按下阴影。

  1. const ActionChip({
  2. Key key,
  3. this.avatar,
  4. @required this.label,
  5. this.labelStyle,
  6. this.labelPadding,
  7. @required this.onPressed,
  8. this.pressElevation,
  9. this.tooltip,
  10. this.shape,
  11. this.clipBehavior = Clip.none,
  12. this.backgroundColor,
  13. this.padding,
  14. this.materialTapTargetSize,
  15. this.elevation,
  16. })

ChoiceChip

ChoiceChip 多了一个selected选中回调。

  1. const ChoiceChip({
  2. Key key,
  3. this.avatar,
  4. @required this.label,
  5. this.labelStyle,
  6. this.labelPadding,
  7. this.onSelected,
  8. this.pressElevation,
  9. @required this.selected,
  10. this.selectedColor,
  11. this.disabledColor,
  12. this.tooltip,
  13. this.shape,
  14. this.clipBehavior = Clip.none,
  15. this.backgroundColor,
  16. this.padding,
  17. this.materialTapTargetSize,
  18. this.elevation,
  19. this.avatarBorder = const CircleBorder(),
  20. })

示例
014.png

  1. Column(
  2. crossAxisAlignment: CrossAxisAlignment.start,
  3. children: <Widget>[
  4. Chip(
  5. label: Text('一般Chip'),
  6. ),
  7. Chip(
  8. avatar: CircleAvatar(backgroundColor: Colors.grey.shade800, child: new Icon(Icons.bluetooth)),
  9. label: Text('带图标Chip'),
  10. ),
  11. Chip(
  12. avatar: CircleAvatar(backgroundColor: Colors.grey.shade800, child: new Icon(Icons.bluetooth)),
  13. label: Text('带图标带删除Chip'),
  14. deleteIcon: new Icon(
  15. Icons.delete,
  16. color: Colors.red,
  17. ),
  18. onDeleted: () {
  19. print("点击了删除");
  20. },
  21. deleteButtonTooltipMessage: "点击删除",
  22. ),
  23. Chip(
  24. avatar: CircleAvatar(backgroundColor: Colors.grey.shade800, child: Text('A')),
  25. label: Text('padding为0的Chip'),
  26. padding: EdgeInsets.all(0),
  27. ),
  28. Chip(
  29. avatar: CircleAvatar(backgroundColor: Colors.grey.shade800, child: Text('A')),
  30. label: Text('padding为10的Chip'),
  31. padding: EdgeInsets.all(10),
  32. ),
  33. Chip(
  34. avatar: CircleAvatar(backgroundColor: Colors.grey.shade800, child: Text('A')),
  35. label: Text('改背景颜色和圆角的Chip', style: TextStyle(color: Colors.white)),
  36. backgroundColor: Colors.red.shade500,
  37. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
  38. ActionChip(
  39. avatar: CircleAvatar(backgroundColor: Colors.grey.shade800, child: Text('B')),
  40. label: Text('带事件的Chip'),
  41. onPressed: () {
  42. print("点击了ActionChip");
  43. },
  44. ),
  45. ActionChip(
  46. avatar: CircleAvatar(backgroundColor: Colors.grey.shade800, child: Text('B')),
  47. label: Text('带阴影的Chip'),
  48. onPressed: () {},
  49. elevation: 5,
  50. pressElevation: 20,
  51. ),
  52. ],
  53. );

二、Card

Card: 卡片

示例:
015.png

  1. Container(
  2. constraints: BoxConstraints(maxWidth: 300),
  3. child: Card(
  4. child: Column(
  5. mainAxisSize: MainAxisSize.min,
  6. children: <Widget>[
  7. const ListTile(
  8. leading: Icon(Icons.album),
  9. title: Text('The Enchanted Nightingale'),
  10. subtitle: Text('Music by Julie Gable. Lyrics by Sidney Stein.'),
  11. ),
  12. ButtonTheme.bar( // make buttons use the appropriate styles for cards
  13. child: ButtonBar(
  14. children: <Widget>[
  15. FlatButton(
  16. child: const Text('BUY TICKETS'),
  17. onPressed: () { /* ... */ },
  18. ),
  19. FlatButton(
  20. child: const Text('LISTEN'),
  21. onPressed: () { /* ... */ },
  22. ),
  23. ],
  24. ),
  25. ),
  26. ],
  27. ),
  28. ),
  29. )

三、ListTile

ListTile: 显示带文本及图片, 通常用在 Card 组件中

示例:
016.png

  1. ListTile(
  2. leading: FlutterLogo(),
  3. title: Text('The Enchanted Nightingale'),
  4. subtitle: Text('Music by Julie Gable. Lyrics by Sidney Stein.'),
  5. trailing: Icon(Icons.more_vert),
  6. dense: true,
  7. isThreeLine: true,
  8. onTap: () { print(1); },
  9. enabled: true,
  10. )