// Chip组件
class ChipDemo extends StatelessWidget {
List<String> _tag = ['Android', 'ios', 'windows'];
@override
Widget build(BuildContext context) {
return ListView(
children: [
Chip(
label: Text('Flutter'),
),
Chip(
label: Text('Flutter'),
backgroundColor: Colors.orange,
),
Chip(
label: Text('Flutter'),
avatar: CircleAvatar(
backgroundColor: Colors.green,
child: Text('Flutter'),
),
),
Chip(
label: Text('Flutter'),
avatar: CircleAvatar(
backgroundImage: ExactAssetImage('assets/view.jpg'),
child: Text('Flutter'),
),
),
Chip(
label: Text('Flutter'),
// 删除回调
onDeleted: () {},
// 删除图标
deleteIcon: Icon(Icons.delete),
// 删除图标颜色
deleteIconColor: Colors.redAccent,
// 删除提示
deleteButtonTooltipMessage: '删除这个标签',
),
Wrap(
spacing: 8.0,
children: _tag.map((e) => Chip(
label: Text('Android'),
onDeleted: () {
},
)).toList(),
),
Wrap(
spacing: 8.0,
children: _tag.map((e) => ActionChip(
label: Text('Android'),
onPressed: () { },
)).toList(),
),
Wrap(
spacing: 8.0,
children: _tag.map((e) => FilterChip(
label: Text('Android'),
selected: e == 'Android',
onSelected: (bool value) {
},
)).toList(),
),
Wrap(
spacing: 8.0,
children: _tag.map((e) =>ChoiceChip(
label: Text('Android'),
selected: e == 'Android',
selectedColor: Colors.redAccent,
onSelected: (bool value) {
},
)).toList(),
)
],
);
}
}
Flutter的Chip标签组件
最新推荐文章于 2025-04-12 19:49:26 发布