drop_down_demo.dart 1.05 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';

Hixie's avatar
Hixie committed
7
class DropDownDemo extends StatefulComponent {
8
  _DropDownDemoState createState() => new _DropDownDemoState();
9 10
}

11
class _DropDownDemoState extends State<DropDownDemo> {
12
  String value = "Free";
13

14 15
  List<DropDownMenuItem<String>> buildItems() {
    return <String>["One", "Two", "Free", "Four"].map((String value) {
Hixie's avatar
Hixie committed
16
      return new DropDownMenuItem<String>(value: value, child: new Text(value));
17 18 19 20 21
    })
    .toList();
  }

  Widget build(BuildContext context) {
22 23 24 25 26 27 28 29 30 31 32 33 34 35
    return new Scaffold(
      toolBar: new ToolBar(center: new Text("Dropdown Button")),
      body: new Center(
        child: new DropDownButton<String>(
          items: buildItems(),
          value: value,
          onChanged: (String newValue) {
            setState(() {
              if (newValue != null)
                value = newValue;
            });
          }
        )
      )
36 37 38
    );
  }
}