Member-only story
The Best List Handling Methods in Flutter And Dart
We can use a variety of methods in a list, but we’ll look at how we can use a list in a flutter to achieve whatever we want and common ways to use a list effectively.
forEach method
When calling this function, we should pass an anonymous void function as an argument (so it doesn’t return any value).
Let us look at some examples.
As you can see, when we call the foreach method, it applies the function inside the parenthesis for each iteration.
another example
Here we created the “Feelings” model that we wanted, If you started studying flutter you would have created a lot of models. hahahhahaah….. Okay, in this section, we wrote a model that takes the name of the feeling and its color, In our main method we created a list .then we put data as the datatype of our model which we created
I also reinforce that we can only add a void function inside the foreach method. That means you won’t be able to return anything from the function.