Skip to content

Instantly share code, notes, and snippets.

@sunil-singh-chaudhary
Created July 27, 2022 08:04
Show Gist options
  • Save sunil-singh-chaudhary/9d2077e04926f60ba76ff5e5f6580e07 to your computer and use it in GitHub Desktop.
Save sunil-singh-chaudhary/9d2077e04926f60ba76ff5e5f6580e07 to your computer and use it in GitHub Desktop.
List function all with demo flutter
ListDemoWorkExample() {
var myList = [11, 12, 123, 1343, 13, 4, 44, 56, 66];
myList.forEach((element) {
print(element);
});
var newList = ['sun', 'Mon', 'tue', 'wed', 'thr', 'fri', 'sat'];
newList.forEach((element) {
if (element[0] == 't') {
print(element);
}
//new Example map
var data = myList.map((e) => e.toString());
print(data);
int newdata(int elem) {
return elem + elem;
}
//direact call newdata method because bydefalut it it () function below map
var secdata = myList.map((newdata));
print(secdata);
});
//new Method is where() ,fillter() returns element if it is available in list
var newwhereList = myList.where((element) => element > 10);
print(newwhereList);
//reduced() fold()
//compare previous element to the next one
int sum = myList.reduce((value, element) => value + element);
print(sum);
//have intial value only
// int foldedsum = myList.fold(initialValue, (previousValue, element) => null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment