代码
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("搜索记录"),
),
body: Wrap(
spacing: 8.0,// 横向间距
runSpacing: -2.0,//纵向间距
children: [
Chip(
avatar: new CircleAvatar(
backgroundColor: Colors.blue,
child: Text('M'),
),
label: new Text('Mulligansadfsadgasd'),
),
Chip(
avatar: new CircleAvatar(
backgroundColor: Colors.blue,
child: Text('M'),
),
label: new Text('Mulligansaadsgasdgdfsadgasd'),
),
Chip(
avatar: new CircleAvatar(
backgroundColor: Colors.blue,
child: Text('M'),
),
label: new Text('Mdgasd'),
),
Chip(
avatar: new CircleAvatar(
backgroundColor: Colors.blue,
child: Text('M'),
),
label: new Text('Mgasd'),
),
Chip(
avatar: new CircleAvatar(
backgroundColor: Colors.blue,
child: Text('M'),
),
label: new Text('Mullfsadgasd'),
)
],
)
);
}
}
- Wrap
spacing:横轴方向子widget的间距
alignment: 横轴对其方式
runSpacing:纵轴方向的间距
runAlignment:纵轴方向的对齐方式
Wrap({
Key key,
this.direction = Axis.horizontal,
this.alignment = WrapAlignment.start,
this.spacing = 0.0,
this.runAlignment = WrapAlignment.start,
this.runSpacing = 0.0,
this.crossAxisAlignment = WrapCrossAlignment.start,
this.textDirection,
this.verticalDirection = VerticalDirection.down,
List children = const [],
}) : super(key: key, children: children);
- Chip
Chip({
Key key,
this.avatar,//标签左侧Widget,一般为小图标
@required this.label,//标签
this.labelStyle,
this.labelPadding,//padding
this.deleteIcon//删除图标,
this.onDeleted//删除回调,为空时不显示删除图标,
this.deleteIconColor//删除图标的颜色,
this.deleteButtonTooltipMessage//删除按钮的tip文字,
this.shape//形状,
this.clipBehavior = Clip.none,
this.backgroundColor//背景颜色,
this.padding,
this.materialTapTargetSize//删除图标material点击区域大小,
})
Flutter之CircleAvatar组件,圆形和圆角图片
Wrap
Chip