'How to get data index from List Dart
I have the list data like this
void main() {
var animals = [
{
"0": ["cow", "chicken", "Fish"]
},
{
"1": ["lamb", "Camel"]
},
{
"2": ["Goat", "Cat"]
}
];
print(animals.length);
for (var a in animals) {
for (final x in a.entries){
print (x.value)}
}
}
but I want to get data to become like this:
1. cow
2. chicken
3. fish
1. lamb
2. camel
1. goat
2. cat
So, what can I do to get the output? Thank you I have tried to use join, but it is just for making a new line. not get the index.
Using x.value.join("\n")
Solution 1:[1]
try using .indexWhere and use a filter that includes all of your data. (https://www.kindacode.com/snippet/dart-flutter-get-the-index-of-a-specific-element-in-a-list/#:~:text=In%20Dart%2C%20the%20List%20class,that%20satisfies%20the%20given%20conditions.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Golden Lion |


