Skip to content

Instantly share code, notes, and snippets.

@Blasanka
Created July 8, 2018 13:12
Show Gist options
  • Save Blasanka/bb0a2cd7623635bf9da967d0a25e94fd to your computer and use it in GitHub Desktop.
Save Blasanka/bb0a2cd7623635bf9da967d0a25e94fd to your computer and use it in GitHub Desktop.
replace items in a list or update items in a list in dart
//The easy way:
void main() {
var collection=[0, 1, 2];
for(int i = 0; i < collection.length; i++) {
collection[i] += 1;
}
print(collection);
}
//Using replaceRange:
void main() {
var collection=[0, 1, 2];
var temp = collection.map((c) => c+1).toList();
collection.replaceRange(0, collection.length, temp);
print(collection);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment