和Chip组件类似的样式,集成了点击、删除、选择事件为一体。注意:点击事件和选择事件不能同时存在。

相关组件

Chip ChoiceChip ActionChip FilterChip RawChip

可以接受点击、删除事件

【onPressed】: 点击事件 【Function()】
【onDeleted】: 删除事件 【Function()】
15.gif

  1. import 'package:flutter/material.dart';
  2. class PressInputChip extends StatefulWidget {
  3. @override
  4. _PressInputChipState createState() => _PressInputChipState();
  5. }
  6. class _PressInputChipState extends State<PressInputChip> {
  7. bool _delete = false;
  8. @override
  9. Widget build(BuildContext context) {
  10. return InputChip(
  11. padding: EdgeInsets.all(5),
  12. labelPadding: EdgeInsets.all(3),
  13. label: Text(
  14. !_delete ?
  15. "This is a InputChip." :
  16. "You are clicked delete icon."),
  17. backgroundColor: Colors.grey.withAlpha(66),
  18. avatar: Image.asset("assets/images/icon_head.png"),
  19. selectedColor: Colors.orangeAccent.withAlpha(88),
  20. selectedShadowColor: Colors.blue,
  21. shadowColor: Colors.orangeAccent,
  22. elevation: 3,
  23. onPressed: () => Navigator.of(context).pushNamed('AboutMePage'),
  24. onDeleted: () => setState(() => _delete = !_delete));
  25. }
  26. }

可以接受选中事件

【selected】: 是否选中 【bool】
【onSelected】: 选中事件 【Function(bool)】
16.gif

import 'package:flutter/material.dart';
class SelectInputChip extends StatefulWidget {
  @override
  _SelectInputChipState createState() => _SelectInputChipState();
}

class _SelectInputChipState extends State<SelectInputChip> {
  bool _select = false;

  @override
  Widget build(BuildContext context) {
    return InputChip(
      selected: _select,
      padding: EdgeInsets.all(5),
      labelPadding: EdgeInsets.all(3),
      label: Text("This is a InputChip."),
      backgroundColor: Colors.grey.withAlpha(66),
      avatar: Image.asset("assets/images/icon_head.png"),
      selectedColor: Colors.orangeAccent.withAlpha(88),
      selectedShadowColor: Colors.blue,
      shadowColor: Colors.orangeAccent,
      elevation: 3,
      onDeleted: () =>  Navigator.of(context).pushNamed('AboutMePage'),
      onSelected: (bool value) {
        setState(() {
          _select = value;
        });
        print("onSelected");
      },
    );
  }
}