我被一个不填充任何数据的 DrowdownButton 卡住了。
它是从上一个屏幕传递的列表中填充的。
我的调试表明该列表具有可以解析的数据。输出只产生一个空的 DropdownButton。
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'menuList.dart';
import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart' show CalendarCarousel;
class OrderInitiate extends StatefulWidget {
final List childData;
OrderInitiate(this.childData);
@override
_OrderInitiateState createState() => new _OrderInitiateState();
}
class _OrderInitiateState extends State<OrderInitiate> {
double buttonWidth = 200.0;
DateTime selectedDate = DateTime.now();
DateTime tempDate = DateTime.now();
@override
void initState() {
print("OrderInitiate: initstate begin");
print("ChildData: " + widget.childData.toString());
}
_dateSelected(date) {
setState(() {
selectedDate = date;
});
}
String itemSel;
@override
Widget build(BuildContext context) => new Scaffold(
appBar: new AppBar(title: new Text("Start an Order"), actions:
<Widget>[
]),
body: new Column(
children: <Widget>[
Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("Select child:"),
new DropdownButton<String>(
value: itemSel,
onChanged: null,
hint: Text("Select child"),
items:
widget.childData.map ((item) {
print("DropDownButton item: " + item.toString());
print("Child Id: " + item['ChildId']);
return new DropdownMenuItem<String>(
value: item['ChildId'],
child:
new Text("ChildFirstName"),
);
}).toList(),
),
Text("${selectedDate.toLocal()}"),
SizedBox(
height: 20.0,
),
],
),
),
SizedBox(
width: buttonWidth,
child: RaisedButton(
onPressed: () => _StartOrder(this.context),
child: Text('Start Order'),
),
),
],
),
);
_StartOrder(BuildContext context) {
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) => new MenuList()));
}
}
我的调试行给出以下输出:
DropDownButton 项目:{ParentId:4,ParentLastName:testparent,ParentFirstName:TestParentSur,ParentUserName:TestParent,ChildId:3,ChildLastName:Test2Last,ChildFirstName:Test2,ChildUserName:test2}
孩子编号:3
在过去的两个晚上,我一直被困在这段代码上,所以希望有人能提供帮助。
我研究了许多列表和项目生成教程以及 stackoverflow 项目,但没有运气。