Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
for (var i = 0;i < snapshot.data[0]["meanings"][index]["definitions"].length;i )
for (var item in snapshot.data[0]["meanings"][index]["definitions"])
Text(
(i 1).toString() ". " item["definition"],
textAlign: TextAlign.left,
)
],
),
)
This is the result the code gives:
- A party...
- A hairdo
- Something that.... ...
List should end at 7 which is the length of the array
CodePudding user response:
In order to get rid of unnecessary repetition you just simply have to get rid of your nested for loop, which is totally redundant here. Access your item with loop index - snapshot.data[0]["meanings"][index]["definitions"][i]["definition"]
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
for (var i = 0;i < snapshot.data[0]["meanings"][index]["definitions"].length;i )
Text(
(i 1).toString() ". " snapshot.data[0]["meanings"][index]["definitions"][i]["definition"],
textAlign: TextAlign.left,
)
],
),
)