Interface for classes that can tell their Kind.
If you extend HasKind you should override runtimeKind to return the Kind of the class. This is used by HasKind to implement hashCode, operator ==, and toString.
Example
import 'package:kind/kind.dart';
void main() {
// HasKind mixin gives you `==` and `hashCode`
final person = Person(name: 'Bob');
assert(person == Person(name: 'Bob'));
assert(person.hashCode == Person(name: 'Bob').hashCode);
// HasKind mixin gives you `toString()`
print(person.toString());
}
class Person with HasKind {
static const kind = ImmutableKind<Person>.withConstant(
name: 'Example',
blank: const Person(name: ''),
copy: _copy,
);
final String name;
Kind<Person> get runtimeKind => kind;
const Person({
required this.name,
});
static Person _copy(Mapper f, Person t) {
final name = f<String>.required(t.name, 'name');
if (f.canReturnSame) {
return t;
}
return Person(
name: name,
);
}
}
- Implementers
Constructors
- HasKind()
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
-
runtimeKind
→ Kind<
Object> -
Kind of this object.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override