Last active
February 4, 2025 15:02
-
-
Save knaeckeKami/c3207d7526136d463760fcef954735c0 to your computer and use it in GitHub Desktop.
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
//poor man's data class | |
extension type const User( | |
({String id, String email, String firstName, String lastName}) _) {} | |
void main() { | |
final user = | |
User((id: "1", email: "[email protected]", firstName: "John", lastName: "Doe")); | |
// different instantiation, same values | |
final valueEqualUser = | |
User((id: "1", email: "[email protected]", firstName: "John", lastName: "Doe")); | |
// different values | |
final valueDifferentUser = User( | |
(id: "2", email: "[email protected]", firstName: "Abigail", lastName: "Moe")); | |
print("user == valueEqualUser ${user == valueEqualUser}"); | |
print("user != valueDifferentUser ${user != valueDifferentUser}"); | |
print("automatic toString: ${user.toString()}"); | |
print("automatic hashcode: ${user.hashCode == valueEqualUser.hashCode}"); | |
print("different hashcode: ${user.hashCode != valueDifferentUser.hashCode}"); | |
// immutable, this is a compile time error: | |
// user.email = "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment