Commit d25039df authored by Hans Muller's avatar Hans Muller

Use a type parameter for Dropdown value

parent bd9036cd
...@@ -11,17 +11,17 @@ class DropdownDemo extends StatefulComponent { ...@@ -11,17 +11,17 @@ class DropdownDemo extends StatefulComponent {
} }
class DropdownDemoState extends State<DropdownDemo> { class DropdownDemoState extends State<DropdownDemo> {
dynamic _value = 0; String _value = "Free";
List <DropdownMenuItem> _buildItems() { List <DropdownMenuItem> _buildItems() {
return ["One", "Two", "Free", "Four"].map((String label) { return ["One", "Two", "Free", "Four"].map((String value) {
return new DropdownMenuItem(value: label, child: new Text(label)); return new DropdownMenuItem<String>(value: value, child: new Text(value));
}) })
.toList(); .toList();
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget dropdown = new DropdownButton( Widget dropdown = new DropdownButton<String>(
items: _buildItems(), items: _buildItems(),
value: _value, value: _value,
onChanged: (dynamic newValue) { onChanged: (dynamic newValue) {
......
...@@ -139,7 +139,8 @@ class _MenuRoute extends PerformanceRoute { ...@@ -139,7 +139,8 @@ class _MenuRoute extends PerformanceRoute {
Duration get transitionDuration => _kMenuDuration; Duration get transitionDuration => _kMenuDuration;
Widget build(RouteArguments args) { Widget build(RouteArguments args) {
final Size navigatorSize = navigator.context.findRenderObject().size; final RenderBox renderBox = navigator.context.findRenderObject();
final Size navigatorSize = renderBox.size;
final RelativeRect menuRect = new RelativeRect.fromSize(rect, navigatorSize); final RelativeRect menuRect = new RelativeRect.fromSize(rect, navigatorSize);
return new Positioned( return new Positioned(
...@@ -166,7 +167,7 @@ class _MenuRoute extends PerformanceRoute { ...@@ -166,7 +167,7 @@ class _MenuRoute extends PerformanceRoute {
} }
} }
class DropdownMenuItem extends StatelessComponent { class DropdownMenuItem<T> extends StatelessComponent {
DropdownMenuItem({ DropdownMenuItem({
Key key, Key key,
this.value, this.value,
...@@ -174,7 +175,7 @@ class DropdownMenuItem extends StatelessComponent { ...@@ -174,7 +175,7 @@ class DropdownMenuItem extends StatelessComponent {
}) : super(key: key); }) : super(key: key);
final Widget child; final Widget child;
final dynamic value; final T value;
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Container( return new Container(
...@@ -191,7 +192,7 @@ class DropdownMenuItem extends StatelessComponent { ...@@ -191,7 +192,7 @@ class DropdownMenuItem extends StatelessComponent {
} }
} }
class DropdownButton extends StatelessComponent { class DropdownButton<T> extends StatelessComponent {
DropdownButton({ DropdownButton({
Key key, Key key,
this.items, this.items,
...@@ -200,8 +201,8 @@ class DropdownButton extends StatelessComponent { ...@@ -200,8 +201,8 @@ class DropdownButton extends StatelessComponent {
this.level: 4 this.level: 4
}) : super(key: key); }) : super(key: key);
final List<DropdownMenuItem> items; final List<DropdownMenuItem<T>> items;
final dynamic value; final T value;
final ValueChanged onChanged; final ValueChanged onChanged;
final int level; final int level;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment