我在尝试使用一种在Flutter中使用ListView.builder来显示更复杂的布局的方法时遇到了麻烦。
这里是一个例子Image of the needed layout
亲切的问候
我假设您的_httpCall未来函数返回一个数组,这是您的代码;
FutureBuilder<List>(
future: _httpCall(),
builder: (context, snapshot) {
if (snapshot.hasData)
return ListView.builder(
itemCount: (snapshot.data.length * (2 / 3)).floor(),
itemBuilder: (context, index) {
if (index % 3 == 0)
return Container(
// Your full-width item
width: double.maxFinite,
child: Text("${snapshot.data[index]}"),
);
else
return Row(
children: [
Expanded(
child: Container(
child: Text("${snapshot.data[index]}"),
),
),
Expanded(
child: Container(
child: Text("${snapshot.data[index + 1]}"),
),
),
],
);
},
);
return CircularProgressIndicator();
},
)