chip_demo.dart 1.23 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
  static const String routeName = '/material/chip';
9

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
  Widget build(BuildContext context) {
25
    final List<Widget> chips = <Widget>[
26 27
      const Chip(
        label: const Text('Apple')
28
      ),
29 30
      const Chip(
        avatar: const CircleAvatar(child: const Text('B')),
31
        label: const Text('Blueberry')
32
      ),
33 34 35 36
    ];

    if (_showBananas) {
      chips.add(new Chip(
37
        label: const Text('Bananas'),
38 39 40 41
        onDeleted: _deleteBananas
      ));
    }

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