Fold Dart

Fold Dart :

  • reduce can only be used on non-empty collections with functions that returns the same type as the types contained in the collection.
  • fold can be used in all cases.
    For instance you cannot compute the sum of the length of all strings in a list with reduce.
Fold Dart

iterable.fold(0, (prev, element) => prev + element);

Uses initialValue as the initial value, then iterates through the elements and updates the value with each element using the combine function.

var foldDart =  listASCGiveCharge.fold(0, (t, e) => t + e.amount * e.qty);
print('foldDart' + data.toString());
final list = ['a', 'bb', 'ccc']; // compute the sum of all length
list.fold(0, (t, e) => t + e.length);

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in