我有来自 api 的响应,它有 83 个对象,但是我的应用程序不会呈现超过 39 个错误的项目RangeError (index): Invalid value: Valid value range is empty: 0
,如果我将 itemCount 替换为 39 可以正常工作,我哪里出错了?也许是因为我在 initState 中使用了 setState?我无法显示更多代码,因为论坛阻止了它我的代码在这里:
void initState() {
super.initState();
Future.delayed(Duration(seconds: 1), () {
loadFuture = NetworkUtils.getOrdersByUserId(id);
NetworkUtils.getOrdersByUserId(id).then((value) {
setState(() {
orders = value;
});
});
});
}
class _OrderPageState extends State<OrderPage> {
var orders = [];
Future loadFuture;
Timer timer;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
SizedBox(
height: 8,
),
Expanded(
child: FutureBuilder<dynamic>(
future: loadFuture,
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData &&
snapshot.connectionState != ConnectionState.waiting) {
return ListView.builder(
itemCount: orders.length,
itemBuilder: (BuildContext context, int index) {
return Container(
margin:
EdgeInsets.symmetric(horizontal: 8, vertical: 6),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 3,
color: Color(0xFF12153D).withOpacity(0.2),
),
],
),
child: Text('Here more info ')
),
);
},
);
} else {
//
}
},
),
),
],
),
);
}
}