Add basic support for material chips:

http://www.google.com/design/spec/components/chips.html#chips-behavior

This patch adds support for deletable and non-deleteable chips, but doesn't yet
add support for contact chips. Also, demo the chips in a new Material Gallery
app that will let us demo our gallery of widgets in a single app.
This commit is contained in:
Adam Barth
2015-11-23 10:38:46 -08:00
parent 94c9b232af
commit cc4234821b
8 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
name: material_gallery
material-design-icons:
- name: navigation/cancel

View File

@@ -0,0 +1,51 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'widget_demo.dart';
class ChipDemo extends StatefulComponent {
_ChipDemoState createState() => new _ChipDemoState();
}
class _ChipDemoState extends State<ChipDemo> {
bool _showBananas = true;
void _deleteBananas() {
setState(() {
_showBananas = false;
});
}
Widget build(BuildContext context) {
List<Widget> chips = <Widget>[
new Chip(
label: new Text('Apple')
)
];
if (_showBananas) {
chips.add(new Chip(
label: new Text('Bananas'),
onDeleted: _deleteBananas
));
}
return new Block(chips.map((Widget widget) {
return new Container(
height: 100.0,
child: new Center(
child: widget
)
);
}).toList());
}
}
final WidgetDemo kChipDemo = new WidgetDemo(
title: 'Chips',
route: '/',
builder: (_) => new ChipDemo()
);

View File

@@ -0,0 +1,20 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'widget_demo.dart';
class GalleryPage extends StatelessComponent {
GalleryPage({ this.demo });
final WidgetDemo demo;
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(center: new Text(demo.title)),
body: demo.builder(context)
);
}
}

View File

@@ -0,0 +1,24 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'chip_demo.dart';
import 'gallery_page.dart';
import 'widget_demo.dart';
final List<WidgetDemo> _kDemos = <WidgetDemo>[
kChipDemo
];
void main() {
Map<String, RouteBuilder> routes = new Map<String, RouteBuilder>();
for (WidgetDemo demo in _kDemos)
routes[demo.route] = (_) => new GalleryPage(demo: demo);
runApp(new MaterialApp(
title: 'Material Gallery',
routes: routes
));
}

View File

@@ -0,0 +1,13 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class WidgetDemo {
WidgetDemo({ this.title, this.route, this.builder });
final String title;
final String route;
final WidgetBuilder builder;
}

View File

@@ -0,0 +1,4 @@
name: material_gallery
dependencies:
flutter:
path: ../../packages/flutter