Last active
December 26, 2021 14:52
-
-
Save xros/3c65583640000df2b1bf6060a6944f1b to your computer and use it in GitHub Desktop.
simple copyWith method in Dart
This file contains hidden or 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
// simple copyWith method | |
class Credentials { | |
const Credentials({this.email = '', this.password = ''}); | |
final String email; | |
final String password; | |
Credentials copyWith({String? email, String? password}) { | |
return Credentials( | |
email: email ?? this.email, | |
password: password ?? this.password, | |
); | |
} | |
@override | |
String toString() => "Credentials $email, $password"; | |
} | |
void main() { | |
final cred = Credentials(); | |
print(cred); | |
final newCred = cred.copyWith(email: '[email protected]'); | |
print(newCred); | |
final newCred2 = newCred.copyWith(password: 'asdfsf'); | |
print(newCred2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output