Commit c60bb1b1 authored by Adam Barth's avatar Adam Barth

Merge pull request #552 from abarth/chip_avatar

Add avatars to material chips
parents 0e290946 b823e47f
...@@ -23,7 +23,11 @@ class _ChipDemoState extends State<ChipDemo> { ...@@ -23,7 +23,11 @@ class _ChipDemoState extends State<ChipDemo> {
List<Widget> chips = <Widget>[ List<Widget> chips = <Widget>[
new Chip( new Chip(
label: new Text('Apple') label: new Text('Apple')
) ),
new Chip(
avatar: new CircleAvatar(label: 'B'),
label: new Text('Blueberry')
),
]; ];
if (_showBananas) { if (_showBananas) {
......
...@@ -7,6 +7,9 @@ import 'package:flutter/widgets.dart'; ...@@ -7,6 +7,9 @@ import 'package:flutter/widgets.dart';
import 'colors.dart'; import 'colors.dart';
import 'icon.dart'; import 'icon.dart';
const double _kChipHeight = 32.0;
const double _kAvatarDiamater = _kChipHeight;
const TextStyle _kLabelStyle = const TextStyle( const TextStyle _kLabelStyle = const TextStyle(
inherit: false, inherit: false,
fontSize: 13.0, fontSize: 13.0,
...@@ -21,26 +24,39 @@ final ColorFilter _kIconColorFilter = new ColorFilter.mode( ...@@ -21,26 +24,39 @@ final ColorFilter _kIconColorFilter = new ColorFilter.mode(
class Chip extends StatelessComponent { class Chip extends StatelessComponent {
const Chip({ const Chip({
Key key, Key key,
this.icon, this.avatar,
this.label, this.label,
this.onDeleted this.onDeleted
}) : super(key: key); }) : super(key: key);
final Widget icon; final Widget avatar;
final Widget label; final Widget label;
final VoidCallback onDeleted; final VoidCallback onDeleted;
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bool deletable = onDeleted != null; 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>[ children.add(new DefaultTextStyle(
new DefaultTextStyle( style: _kLabelStyle,
style: _kLabelStyle, child: label
child: label ));
)
];
if (deletable) { if (deletable) {
rightPadding = 0.0;
children.add(new GestureDetector( children.add(new GestureDetector(
onTap: onDeleted, onTap: onDeleted,
child: new Container( child: new Container(
...@@ -54,13 +70,9 @@ class Chip extends StatelessComponent { ...@@ -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( return new Container(
height: 32.0, height: _kChipHeight,
padding: padding, padding: new EdgeDims.only(left: leftPadding, right: rightPadding),
decoration: new BoxDecoration( decoration: new BoxDecoration(
backgroundColor: Colors.grey[300], backgroundColor: Colors.grey[300],
borderRadius: 16.0 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