Skip to content

Instantly share code, notes, and snippets.

class ConstantClass{
const ConstantClass({
required this.arg1,
required this.arg2,
required this.arg3,
});
final int arg1;
final int arg2;
final int arg3;
@yarn-rp
yarn-rp / .dart
Created July 29, 2023 23:33
Example of class using Equatable
class MyClass extends Equatable {
const MyClass(this.id);
final int id;
@override
List<Object> get props => [id];
}
@yarn-rp
yarn-rp / .dart
Created July 29, 2023 23:38
Equatable code for overriding == and hashcode
abstract class Equatable {
/// {@macro equatable}
const Equatable();
...
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Equatable &&
runtimeType == other.runtimeType &&
@yarn-rp
yarn-rp / .dart
Last active July 30, 2023 00:04
testing example using consts and MyClass
void main() {
 test('Value equality', () {
const a = MyClass(1);
const b = MyClass(1);
expect(a, b); // The props is not invoked.
 });
}
@yarn-rp
yarn-rp / .dart
Created July 31, 2023 22:33
example using nonConstMyClass version
MyClass nonConstMyClass(int value) => MyClass(value);
void main() {
test('ValueEquality', (){
final a = nonConstMyClass(1);
final b = nonConstMyClass(2);
expect(a, b);
});
}
@yarn-rp
yarn-rp / .dart
Created December 3, 2024 15:41
Advent of Code Day 1
import 'package:collection/collection.dart';
final input = '''38665 13337
84587 21418
93374 50722
68298 57474
54771 18244
49242 83955
66490 44116
65908 51323