Created
March 8, 2019 08:45
-
-
Save wtoalabi/b466f5ed3cf37d1c913935a1d96878ad to your computer and use it in GitHub Desktop.
Updating a map in an array (Dart)
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
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