【发布时间】:2020-02-27 19:54:09
【问题描述】:
我在颤振中将 json 数据传递给新的有状态小部件。我可以在调试控制台中看到数据不为空,但有状态的小部件接收到空数据。
我尝试了其他传递数据类型,但仍然不起作用。
我该如何解决这个问题?任何帮助
这里是代码
导航代码
void goToFilteredList() async {
jsonData =await postQuotationFilteredList(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
false,
false,
null,
null);
print(jsonData);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FilteredQuotationList(jsonData)));
}
有状态的小部件
class FilteredQuotationList extends StatefulWidget {
final List<Map<String, dynamic>> jsonData;
FilteredQuotationList(this.jsonData);
static const String routeName = "/filteredquotationlist";
@override
State<StatefulWidget> createState() =>
FilteredQuotationListScreen(this.jsonData);
}
jsonData 具有相同的类型,并且有缺点,此代码接收到空数据。
class FilteredQuotationListScreen extends State<FilteredQuotationList> {
List<Map<String, dynamic>> jsonData;
FilteredQuotationListScreen(List<Map<String, dynamic>> jsonData) {
this.jsonData = jsonData;
}
@override
Widget build(BuildContext context) {
print("filtreleme ekranı");
print(jsonData);
return Scaffold(
body: quotationFilteredListItems(jsonData),
);
}
ListView quotationFilteredListItems(List<Map<String, dynamic>> jsonData) {
print("quotation filtered list items");
List<GetQuotationModel> getQuotationModel =
GetQuotationModel.fromJson(jsonData);
print(getQuotationModel.length);
return ListView.builder(
itemCount: 3,
itemBuilder: (BuildContext context, int position) {
return Card(
color: Colors.amberAccent,
elevation: 2.0,
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.green,
child: Text("getQuotationModel.quoteNumber"),
),
title: Text("this."),
),
);
},
);
}
}
【问题讨论】: