How to get data index from List Dart

202

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.)

Share:
202
Admin
Author by

Admin

Updated on January 04, 2023

Comments

  • Admin
    Admin over 1 year

    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")

    • Christian H
      Christian H about 2 years
      Please use code blocks instead of images