Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Shuvo8693/1eae8ee662f3de0815f139b827b0cd23 to your computer and use it in GitHub Desktop.
Save Shuvo8693/1eae8ee662f3de0815f139b827b0cd23 to your computer and use it in GitHub Desktop.
added the List Items by Loop or Iteration
add List of sum in a sigle value by this way -------------------------------
void main() {
List<double> itemPrice= [15.99, 18.75, 21.40, 53.09];
double sum=0;
double totalPrice=0;
var numbers= itemPrice.map((value)=> value).reduce((previous,present)=>previous+present); // we can use also fold() function
// for (double item in itemPrice) {
// sum+=item;
// totalPrice= sum * 1.05; // eta 5% vat soho
// }
print(numbers); // output 109.23
}
----------------------------------------------------------------fold()-------------------------------
void main() {
List<double> itemPrice= [15.99, 18.75, 21.40, 53.09];
double addedPrice=itemPrice.fold(0,(previous,current)=>previous+current);
double totalPrice= addedPrice * 1.05;
print(totalPrice);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment