mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

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.
58 lines
1.4 KiB
Dart
58 lines
1.4 KiB
Dart
// 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(),
|
|
}
|
|
));
|
|
}
|