Skip to content

Instantly share code, notes, and snippets.

@Nikzed
Created October 4, 2023 08:24
Show Gist options
  • Save Nikzed/5fdaad2901e61469f4663811c3215b61 to your computer and use it in GitHub Desktop.
Save Nikzed/5fdaad2901e61469f4663811c3215b61 to your computer and use it in GitHub Desktop.
Equatable test
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