Created
March 5, 2021 18:26
-
-
Save danielgomezrico/e5da4c33beee65138dd8a7359cc69d1f to your computer and use it in GitHub Desktop.
Example showing how to update a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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