Request<T> class
Request is a listenable data source that loads data in either synchronous or asynchronous manner.
Similar to Future and Stream, Request can hold 3-state result, which could data
, error
or waiting
.
Unlike Future and Stream, Request also provide method to read or write result in both synchronous or asynchronous way.
Request is designed to be used with BuildAsyncSnapshot protocol.
It can be consumed with BuildAsyncSnapshotActions.buildRequest
as same as Future and Stream.
Request is abstract class, a derived class should be created for particular use case. Derived class should at least implement load method to explicitly specify how request should load data.
load can be either synchronous or asynchronous, it can return the result directly if data can be loaded synchronously
- Returns value directly if result can be loaded synchronously
- Returns a Future that holds result if data loaded asynchronously
load method should do its job without any parameters, consider to add parameters required by load method as Request's field. Depends on whether those parameter fields are mutable or final,Request can be either mutable or immutable.
Request only start to load data when Request.resultStream is listened, typically it is when Request is listenable by a widget with BuildAsyncSnapshot protocol. This behavior can be customized for different scenarios:
The loading behaviour of Request can be customized for different scenario, check document for Request constructor for more detail
Request is designed to handle asynchronous scenario, so its API is more complex and could be more expensive to instantiate. To deal with synchronous data only, consider use ResultNotifier instead of Request
Constructors
Properties
- currentData → T
-
Get latest data.
read-only
- currentError → Object
-
Get latest error
read-only
- currentErrorStackTrace → StackTrace
-
Get latest stack trace of latest error
read-only
- ensuredCurrentData → T
-
Similar to currentData, but throws StateError when data is not available
read-only
-
firstResult
→ Future<
T> -
Returns a future which resolves when first data or error fetched
read-only
- hasError → bool
-
Check whether request has a error
read-only
- hashCode → int
-
The hash code for this object.
read-only, inherited
- hasResult → bool
-
Check whether request has a data or an error.
read-only
- hasValue → bool
-
Check whether request has a data
read-only
- isLoading → bool
-
Check whether request is in loading state
read-only
-
resultStream
→ Stream<
T> -
The stream that provides the latest result of current request
read-only
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
execute(
FutureOr< T> action(), {bool quiet = false}) → Future -
Execute the
action
, updates request with the return value from action. -
load(
) → FutureOr< T> - Contract that specifies how request loads data
-
markAsLoading(
) → void - Update request as loading synchronously
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited
-
putError(
Object error, [StackTrace stackTrace]) → void -
Update request with
error
synchronously -
putValue(
T value) → void -
Update request with
value
synchronously -
reload(
{dynamic quiet = false}) → Future - Enforce a request to reload data with current parameters
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
FutureOr< T> value, {dynamic quiet = false}) → Future -
Update request with
value
either synchronously or asynchronously -
updateValue(
ValueUpdater< T> updater) → void -
Update request with
updater
synchronously -
updateValueAsync(
AsyncValueUpdater< T> updater, {dynamic quiet = false}) → Future -
Update request with
updater
asynchronously
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited