您的代码不清楚,因此我为您添加了完整的示例。
import 'package:flutter/material.dart';
void main() => runApp(Home());
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home:MultipleDropDownPage()
);
}
}
class MultipleDropDownPage extends StatefulWidget {
MultipleDropDownPage({Key key}) : super(key: key);
@override
_MultipleDropDownPageState createState() => new _MultipleDropDownPageState();
}
class _MultipleDropDownPageState extends State {
String selectedValues;
@override
void initState() {
// TODO: implement initState
super.initState();
selectedValues = "1";
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: Text('Multi Drop'),
),
body: Column(
children: [
new Text(selectedValues.toString()),
new DropdownButton(
onChanged: (String value) {
setState(() {
selectedValues = value;
});
},
hint: new Text('Course Unit'),
value: selectedValues,
items: ["1", "2", "3", "4", "5"].map((String value) {
return new DropdownMenuItem(
value: value,
child: new Text(value),
);
}).toList(),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
});
},
),
);
}
}