There is no way to return a value from forEach . Just use a for loop instead. On top of that, the Dart style guide specifically recommends using a for loop over a forEach unless you can reuse an existing function.
Read moreWhat is loop in Dart?
Dart Loop is used to run a block of code repetitively for a given number of times or until matches the specified condition . Loops are essential tools for any programming language. It is used to iterate the Dart iterable such as list, map, etc. and perform operations for multiple times.
Read moreHow does a for loop work in Dart?
The for loop is an implementation of a definite loop. The for loop executes the code block for a specified number of times . It can be used to iterate over a fixed set of values, such as an array.
Read moreWhat is an object in Dart?
Objects are basic building blocks of a Dart program . An object is a combination of data and methods. The data and the methods are called members of an object. Objects communicate together through methods. Each object can receive messages, send messages and process data.
Read moreHow do you use if else in flutter?
Ways to Use If Else Statement in Flutter Widget
Read moreHow do you use else in darts?
Dart if else-if Statement
Read moreHow do I add an if else in widget flutter?
How to use Conditional Statement (IF ELSE) on Child Widget in…
Read more