SyncProviderTransformerMixin<InT, ValueT> mixin
base
A mixin for custom ProviderListenables that do not emit AsyncValue.
If in error state, an exception will happen when trying to read the state of this listenable.
Usage
To use this mixin, you must implement the transform
method, along with
the source
getter. The source
will be the original provider that you are transforming.
And transform
is where your transformation logic will be defined.
The following example implements a variable of ProviderListenableSelect.select, where the callback returns a boolean instead of the selected value.
final class Where<T> with SyncProviderTransformerMixin<T, T> {
Where(this.source, this.where);
@override
final ProviderListenable<T> source;
final bool Function(T previous, T value) where;
@override
ProviderTransformer<T, T> transform(
ProviderTransformerContext<T, T> context,
) {
return ProviderTransformer(
initState: (_) => context.sourceState.requireValue,
listener: (self, previous, next) {
if (where(previous, next))
self.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:
- ProviderTransformer, the object responsible for the transformation logic.
- Implemented types
-
- ProviderListenable<
StateT>
- ProviderListenable<
- Available extensions
- @publicInMisc
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
source
→ ProviderListenable<
InT> -
The source of this transformer.
no setterinherited
Methods
-
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
-
transform(
ProviderTransformerContext< InT, ValueT> context) → ProviderTransformer<InT, ValueT> -
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited