Commit b823e47f authored by Adam Barth's avatar Adam Barth

Add avatars to material chips

Fixes #464
parent 0e290946
......@@ -23,7 +23,11 @@ class _ChipDemoState extends State<ChipDemo> {
List<Widget> chips = <Widget>[
new Chip(
label: new Text('Apple')
)
),
new Chip(
avatar: new CircleAvatar(label: 'B'),
label: new Text('Blueberry')
),
];
if (_showBananas) {
......
......@@ -7,6 +7,9 @@ import 'package:flutter/widgets.dart';
import 'colors.dart';
import 'icon.dart';
const double _kChipHeight = 32.0;
const double _kAvatarDiamater = _kChipHeight;
const TextStyle _kLabelStyle = const TextStyle(
inherit: false,
fontSize: 13.0,
......@@ -21,26 +24,39 @@ final ColorFilter _kIconColorFilter = new ColorFilter.mode(
class Chip extends StatelessComponent {
const Chip({
Key key,
this.icon,
this.avatar,
this.label,
this.onDeleted
}) : super(key: key);
final Widget icon;
final Widget avatar;
final Widget label;
final VoidCallback onDeleted;
Widget build(BuildContext context) {
final bool deletable = onDeleted != null;
double leftPadding = 12.0;
double rightPadding = 12.0;
List<Widget> children = <Widget>[];
if (avatar != null) {
leftPadding = 0.0;
children.add(new Container(
margin: const EdgeDims.only(right: 8.0),
width: _kAvatarDiamater,
height: _kAvatarDiamater,
child: avatar
));
}
List<Widget> children = <Widget>[
new DefaultTextStyle(
style: _kLabelStyle,
child: label
)
];
children.add(new DefaultTextStyle(
style: _kLabelStyle,
child: label
));
if (deletable) {
rightPadding = 0.0;
children.add(new GestureDetector(
onTap: onDeleted,
child: new Container(
......@@ -54,13 +70,9 @@ class Chip extends StatelessComponent {
));
}
EdgeDims padding = deletable ?
new EdgeDims.only(left: 12.0) :
new EdgeDims.symmetric(horizontal: 12.0);
return new Container(
height: 32.0,
padding: padding,
height: _kChipHeight,
padding: new EdgeDims.only(left: leftPadding, right: rightPadding),
decoration: new BoxDecoration(
backgroundColor: Colors.grey[300],
borderRadius: 16.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment