Skip to content

Instantly share code, notes, and snippets.

@wtoalabi
Created March 8, 2019 08:45
Show Gist options
  • Save wtoalabi/b466f5ed3cf37d1c913935a1d96878ad to your computer and use it in GitHub Desktop.
Save wtoalabi/b466f5ed3cf37d1c913935a1d96878ad to your computer and use it in GitHub Desktop.
Updating a map in an array (Dart)
main() {
List<User> users = [
User(lastName: "Mesut", firstName: "Ozil"),
User(lastName: "Becham", firstName: "David"),
User(lastName: "Samir", firstName: "Nasri"),
User(lastName: "Arteta", firstName: "Mikel"),
];
User userOLD = users.firstWhere((user){
return user.firstName == "Mikel";
});
users[users.indexOf(userOLD)] = User(lastName: "ARTETER", firstName: "MIKELLOOO");
print(users);
}
class User{
final String firstName;
final String lastName;
User({this.firstName, this.lastName});
@override
String toString() {
return 'User{firstName: $firstName, lastName: $lastName}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment