Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created March 5, 2021 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/e5da4c33beee65138dd8a7359cc69d1f to your computer and use it in GitHub Desktop.
Save danielgomezrico/e5da4c33beee65138dd8a7359cc69d1f to your computer and use it in GitHub Desktop.
Example showing how to update a list
class Person {
Person(this.name);
final String name;
String toString() => name;
}
void main() {
final items = [Person("juan"), Person("pedro"), Person("coso")];
print("before update:");
print(items);
final index = items.indexWhere((p) => p.name == 'pedro');
if (index != -1) {
items[index] = Person("otro");
}
print("after update:");
print(items);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment