【发布时间】:2019-10-01 13:25:13
【问题描述】:
当用户在下拉列表 A 中选择一个值时,此小部件在向 url 发出请求后创建下拉菜单项,但是当用户更改下拉列表 A 的值时,我得到错误。我尝试研究此错误,但没有找到有用的答案。
代码如下
FutureBuilder(
future: listProductsPrice(currentProducts),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: DropdownButton(
hint: Text("Preço"),
value: currentPriceProducts,
items: null,
onChanged: (selected) {},
),
);
} else {
List<PriceProducts> priceProducts = snapshot.data;
return _listViewProductsPrice(priceProducts, "Preço");
}
}),
Widget _listViewProductsPrice(List<PriceProducts> priceProducts, title) {
return Container(
color: Color.fromRGBO(245, 242, 240, 0.20),
child: DropdownButton(
hint: Text(title),
value: currentPriceProducts,
items: priceProducts.map((products) {
return DropdownMenuItem(
value: products.value,
child: Container(
child: Text(
products.value,
style: TextStyle(fontSize: 13),
)),
);
}).toList(),
onChanged: (selected) {
// widget.objMobileRecharge.area_code = int.parse(selected);
print(selected);
setState(() {
currentPriceProducts = selected;
});
},
));
}
有人知道如何解决这个问题吗?
'package:flutter/src/material/dropdown.dart': Failed assertion: line 560 pos 15: 'items == null || I/flutter (11514): items.isEmpty || value == null || items.where((DropdownMenuItem item) => item.value == I/flutter (11514): value).length == 1': is not true.
【问题讨论】: