Created
October 4, 2023 08:24
-
-
Save Nikzed/5fdaad2901e61469f4663811c3215b61 to your computer and use it in GitHub Desktop.
Equatable test
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
import 'package:equatable/equatable.dart'; | |
void main() { | |
Immutable i = const Immutable(0); | |
Set<Immutable> setI = {i}; | |
print(setI.contains(const Immutable(0))); // Prints: true | |
i = i.copyWith(x: 1); | |
print(setI.contains(const Immutable(1))); // Prints: false | |
print(setI.contains(setI.first)); // Prints: true | |
} | |
class Immutable extends Equatable { | |
final int x; | |
const Immutable(this.x); | |
@override | |
List<Object?> get props => [x]; | |
Immutable copyWith({ | |
int? x, | |
}) { | |
return Immutable( | |
x ?? this.x, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment