CustomProviderListenable<InT, ValueT> class
abstract
A ProviderListenable whose value is derived from transforming another ProviderListenable (source).
This is the base class for implementing custom variants of methods such as ProviderListenableSelect.select.
Usage
To use this class, you must implement the source. getter (the provider that is being transformed) and createTransformer (the object responsible for computing/holding the transformed state, see ProviderTransformer2).
The following example implements a variant of ProviderListenableSelect.select, where the callback returns a boolean instead of the selected value.
final class Where<T> extends CustomProviderListenable<T, T> {
Where(this.source, this.where);
@override
final ProviderListenable<T> source;
final bool Function(T previous, T value) where;
@override
_WhereTransformer<T> createTransformer() => _WhereTransformer<T>();
}
final class _WhereTransformer<T>
extends SyncProviderTransformer2<T, T, Where<T>> {
@override
T initState() => sourceState.requireValue;
@override
void onEvent(
AsyncResult<T> prev,
AsyncResult<T> next,
) {
if (listenable.where(prev.requireValue, next.requireValue)) {
state = next;
}
}
}
extension<T> on ProviderListenable<T> {
ProviderListenable<T> where(
bool Function(T previous, T value) where,
) => Where<T>(this, where);
}
Used as ref.watch(provider.where((previous, value) => value > 0)).
See also:
- ProviderTransformer2, the object responsible for the transformation logic.
- Implemented types
-
- ProviderListenable<
ValueT>
- ProviderListenable<
- Available extensions
- Annotations
-
- @publicInMisc
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
listenable
→ ProviderListenable<
ValueListenable< T> > -
Available on ProviderListenable<
Exposes aT> , provided by the ProviderListenableListenable extensionValueListenablethat tracks the state of this provider.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
source
→ ProviderListenable<
InT> -
The source of this transformer.
no setter
Methods
-
createTransformer(
) → ProviderTransformer2< InT, ValueT, CustomProviderListenable< InT, ValueT> > - Creates the ProviderTransformer2 responsible for computing and holding the state of this CustomProviderListenable.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
select<
OutT> (OutT selector(InT value)) → ProviderListenable< OutT> -
Available on ProviderListenable<
Partially listen to a provider.InT> , provided by the ProviderListenableSelect extension -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited