FusionViewModel class abstract
Base class for all ViewModels in the Fusion framework.
Provides lifecycle management, state management, and reactive capabilities. All ViewModels should extend this class to get access to:
- Lifecycle methods (onInit, onReady, onClose)
- ViewState management
- Error handling
- Reactive variables support
Example usage:
class UserViewModel extends FusionViewModel {
final _users = RxValue<List<User>>([]);
List<User> get users => _users.value;
@override
Future<void> onReady() async {
await loadUsers();
}
Future<void> loadUsers() async {
setBusy();
try {
final users = await userService.getUsers();
_users.value = users;
setSuccess();
} catch (e) {
setError('Failed to load users');
}
}
}
- Inheritance
-
- Object
- ChangeNotifier
- FusionViewModel
- Implementers
Constructors
- FusionViewModel()
- Constructor
Properties
- disposed → bool
-
no setter
- errorMessage → String?
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- initialized → bool
-
no setter
- isBusy → bool
-
Convenience getters for view states
no setter
- isEmpty → bool
-
no setter
- isError → bool
-
no setter
- isIdle → bool
-
no setter
- isSuccess → bool
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- viewState → ViewState
-
no setter
Methods
-
addDisposable(
ChangeNotifier disposable) → void - Adds a disposable resource to be disposed when the ViewModel is disposed
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
addRxValue(
RxValue rxValue) → void - Adds an RxValue to the disposables list
-
addSubscription(
StreamSubscription subscription) → void - Adds a stream subscription to be disposed when the ViewModel is disposed
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
initialize(
) → Future< void> - Internal initialization method - called by FusionView
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
onClose(
) → Future< void> - Called when the ViewModel is being disposed Override this to perform cleanup logic
-
onDependenciesReady(
) → Future< void> - Called after dependencies are ready but before onReady Override this to perform dependency-based initialization
-
onInit(
) → Future< void> - Called when the ViewModel is first created Override this to perform initialization logic
-
onReady(
) → Future< void> - Called after the view is ready and displayed to the user Override this to perform final initialization (API calls, etc.)
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
runBusyFuture<
T> (Future< T> future, {String? busyMessage, String? successMessage, String? errorMessage(Object error)?}) → Future<T?> - Executes a future and manages the view state automatically
-
setBusy(
[String? message]) → void - Sets the view state to busy (loading)
-
setEmpty(
[String? message]) → void - Sets the view state to empty
-
setError(
String message) → void - Sets the view state to error with an optional error message
-
setIdle(
) → void - Sets the view state to idle and clears any error message
-
setSuccess(
[String? message]) → void - Sets the view state to success and clears any error message
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited