chip_demo.dart 1.21 KB
Newer Older
1 2 3 4 5 6
// 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';

7
class ChipDemo extends StatefulWidget {
8 9
  static const String routeName = '/chip';

10
  @override
11 12 13 14 15 16 17 18 19 20 21 22
  _ChipDemoState createState() => new _ChipDemoState();
}

class _ChipDemoState extends State<ChipDemo> {
  bool _showBananas = true;

  void _deleteBananas() {
    setState(() {
      _showBananas = false;
    });
  }

23
  @override
24 25 26 27
  Widget build(BuildContext context) {
    List<Widget> chips = <Widget>[
      new Chip(
        label: new Text('Apple')
28 29
      ),
      new Chip(
Hans Muller's avatar
Hans Muller committed
30
        avatar: new CircleAvatar(child: new Text('B')),
31 32
        label: new Text('Blueberry')
      ),
33 34 35 36 37 38 39 40 41
    ];

    if (_showBananas) {
      chips.add(new Chip(
        label: new Text('Bananas'),
        onDeleted: _deleteBananas
      ));
    }

42
    return new Scaffold(
43
      appBar: new AppBar(title: new Text('Chips')),
44 45 46 47 48 49 50 51
      body: new Block(
        children: chips.map((Widget widget) {
          return new Container(
            height: 100.0,
            child: new Center(child: widget)
          );
        }).toList()
      )
52
    );
53 54
  }
}