Adds initial versions of DropdownButton DropdownMenuItem

Adds a dropdown menu button as shown in the Material design spec here: https://www.google.com/design/spec/components/buttons.html#buttons-dropdown-buttons. It's the video at the bottom of this section of the Material design spec.

This version of the component doesn't deal with scrollable menus or
constrain the height of the menu.
This commit is contained in:
Hans Muller
2015-10-21 16:51:16 -07:00
parent de395582d5
commit 33c7820d7e
3 changed files with 315 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
// 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 DropdownDemo extends StatefulComponent {
DropdownDemo();
DropdownDemoState createState() => new DropdownDemoState();
}
class DropdownDemoState extends State<DropdownDemo> {
dynamic _value = 0;
List <DropdownMenuItem> _buildItems() {
return ["One", "Two", "Free", "Four"].map((String label) {
return new DropdownMenuItem(value: label, child: new Text(label));
})
.toList();
}
Widget build(BuildContext context) {
Widget dropdown = new DropdownButton(
items: _buildItems(),
value: _value,
onChanged: (dynamic newValue) {
setState(() {
if (newValue != null)
_value = newValue;
});
}
);
return new Scaffold(
toolBar: new ToolBar(center: new Text('DropdownDemo Demo')),
body: new Container(
decoration: new BoxDecoration(backgroundColor: Theme.of(context).primarySwatch[50]),
child: new Center(child: dropdown)
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'DropdownDemo',
theme: new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: {
'/': (RouteArguments args) => new DropdownDemo(),
}
));
}