- Summary of my problem
I want to know about using listview.builder in listview.builder’s onpressed.
For example, like this.
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return Row(children: [
TextButton(
child: Text(snapshot.data![index].A),
onPressed: () {
ListView.builder(
scrollDirection: Axis.vertical,
itemCount:
snapshot.data![index].B.length,
itemBuilder: (context, index2) {
return Column(children: [
Text(snapshot
.data![index].C
.toString() +
snapshot
.data![index].B[index2]
.toString())
]);
});
},
)
]);
});
- What have I tried so far -
I make code like upper code’s. And tried so many times to make button which create another listview.builder. - Here’s the minimum code you would need to reproduce the problem -
To format your code enter between 3 backticks like this
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return Row(children: [
TextButton(
child: Text(snapshot.data![index].A),
onPressed: () {
ListView.builder(
scrollDirection: Axis.vertical,
itemCount:
snapshot.data![index].B.length,
itemBuilder: (context, index2) {
return Column(children: [
Text(snapshot
.data![index].C
.toString() +
snapshot
.data![index].B[index2]
.toString())
]);
});
},
)
]);
});