答案 0 :(得分:1)
您可以做的是遍历数据库的所有子项,并将它们添加到import 'package:flutter/material.dart';
class FormEG extends StatefulWidget {
@override
_FormEGState createState() => new _FormEGState();
}
class _FormEGState extends State<FormEG> {
List<String> _listValues;
List<DropdownMenuItem<String>> _items;
List<Widget> _widgets;
@override
void initState() {
_listValues = new List<String>();
_listValues.add("b");
_items = new List<DropdownMenuItem<String>>();
_items.add(new DropdownMenuItem(child: Text("a"), value: "a"));
_items.add(new DropdownMenuItem(child: Text("b"), value: "b"));
_items.add(new DropdownMenuItem(child: Text("c"), value: "c"));
_items.add(new DropdownMenuItem(child: Text("d"), value: "d"));
_widgets = new List<Widget>();
_widgets.add(new DropdownButton<String>(
value: _listValues[0],
items: _items,
onChanged: (String newValue) {
setState(() {
_listValues[0] = newValue;
});
},
));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new ListView.builder(
itemCount: _widgets.length,
itemBuilder: (context, index) {
return _widgets[index];
},
));
}
}
中,然后使用数组适配器显示该列表。
我的意思在代码中看起来像这样:
ArrayList