Hook<R> class abstract

What a build uses a HookState by: the description, made anew by each build, that the state its first use created is updated with, as a widget updates its element.

A hook of one's own: the time since the first build, which a later build reads anew.

Duration useElapsed() => use(const _ElapsedHook());

final class _ElapsedHook extends Hook<Duration> {
  const _ElapsedHook();

  @override
  _ElapsedState createState() => _ElapsedState();
}

final class _ElapsedState extends HookState<Duration, _ElapsedHook> {
  final _stopwatch = Stopwatch()..start();

  @override
  Duration build(BuildContext context) => _stopwatch.elapsed;
}

A hook made of other hooks is a function that calls them, as useElapsed above calls use.

Annotations
  • @immutable

Constructors

Hook({List<Object?>? keys})
A hook whose state is kept while keys stay equal; null, the default, keeps it for good.
const

Properties

debugLabel → String
Names the hook in errors and descriptions: its type by default.
no setter
hashCode → int
The hash code for this object.
no setterinherited
keys → List<Object?>?
The state is created anew, the old one disposed first, when these differ from those of the last build's hook (keysEqual); null keeps it.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createState() → HookState<R, Hook<R>>
The state of a first use of this hook.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

keysEqual(List<Object?>? a, List<Object?>? b) → bool
Whether a and b are both null, or as long and their items equal (or identical, as a NaN is to itself) one by one.