Search code examples
flutterdartflutter-dependenciesemojidart-pub

How to Jump to next Element in Dart Lists, (forLoops)


Hey Darting Developers, I want to Seek help. I am Currently Making a Emoji Translator, here i am Getting a Problem that,

List emojis = [
["Happy", "Smile", "Wink", "Tickle"], 
["Silent", "Depressed", "Cry", "Sad"], 
["lichi", "apple", "kiwi", "Banana"]];
  1. I have a Long List
  2. This List is under a List.
  3. I want to Seek only 3 Items from a List.
  4. And then Jump out to Other Item of the Big List.

How to Get Three Items and then Get out of loop and Get inside the another List. and so on. This Question is Bit hard to Understand, but I need to Seek help.


Solution

  • An option is to map over the emojis 2D list and take the first 3 elements.

    final emojis = [
      ["Happy", "Smile", "Wink", "Tickle"], 
      ["Silent", "Depressed", "Cry", "Sad"], 
      ["lichi", "apple", "kiwi", "Banana"]
    ];
      
    final transformedList = emojis.map((sublist) => sublist.take(3).toList());