Service<T> class
abstract
An abstract class that represents the ViewModel in the MVVM architecture pattern.
Primarily responsible for data loading and state management.
- Inheritance
-
- Object
- ChangeNotifier
- Service
- Available extensions
Constructors
- Service({ServiceStatus initialStatus = .none})
Properties
- canRethrow → bool
-
Determines whether this service should rethrow errors from load.
Can be overridden by subclasses to customize behavior.
no setter
- data ↔ T
-
Returns the currently deserialized and loaded data.
getter/setter pair
- error → Object
-
Returns the current error. Throws if no error is present.
no setter
- hasError → bool
-
Returns true if the service encountered an error while fetching data.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isLoading → bool
-
Returns true if the data is currently being loaded or not ready for display.
Typically used to show loading indicators or placeholders.
no setter
- isRefreshing → bool
-
Returns true if the service is currently refreshing its data.
Useful for pull-to-refresh indicators or temporarily disabling
UI interactions.
no setter
- maybeData → T?
-
Returns the current data regardless of its existence.
no setter
- maybeError → Object?
-
Returns the current error regardless of its existence.
no setter
- maybeStackTrace → StackTrace?
-
Returns the current stack trace regardless of its existence.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace
-
Returns the stack trace in the failed state.
no setter
- status → ServiceStatus
-
Returns the current status of the Service.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object.
override
-
done(
T newData) → void - Called when data has been successfully loaded.
-
fail(
Object error, StackTrace stackTrace) → void - Called when a data load fails.
-
fetchData(
) → Future< T> - Fetches the data for this service.
-
load(
{bool isRefresh = false}) → Future< void> - Starts loading or refreshing the data managed by this service.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyChanged(
) → void - Notifies listeners that the service state has changed.
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
onData(
void callback(T data)) → VoidCallback -
Available on Service<
CallsT> , provided by the ServiceExtension extensioncallbackwhenever the service notifies listeners while loaded. -
refresh(
) → Future< void> - Requests a refresh while keeping existing data until new data is loaded.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
request(
) → Future< T> - Loads and returns data for a one-time request.
-
requestOrNull(
) → Future< T?> -
Returns the result of request, or
nullif it throws. -
toString(
) → String -
A string representation of this object.
override
-
when(
{Widget none()?, Widget loading()?, Widget refresh(T data)?, Widget loaded(T data)?, Widget failed(Object error, StackTrace stackTrace)?}) → Widget -
Available on Service<
Returns a widget depending on the current ServiceStatus.T> , provided by the ServiceExtension extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited