RiverViewModel<UISTate> class abstract

A ViewModel class that is used with Riverpod and by default has a corresponding UIState StateController

final _exampleUIStateProvider = StateProvider.autoDispose<ExamplePageUIState>((ref) {
  return ExamplePageUIState();
});

final exampleViewModelProvider = Provider.autoDispose<ExamplePageViewModel>((ref) {
  return ExamplePageViewModel(uiState: ref.watch(_exampleUIStateProvider.notifier));
});

class ExamplePageUIState {
   int counter;

   ExamplePageUIState({this.counter = 0});

   ExamplePageUIState copyWith({int? counter}) {
     return ExamplePageUIState(
       counter: counter ?? this.counter,
     );
   }
}

class ExamplePageViewModel extends RiverViewModel<ExamplePageUIState> {
  ExamplePageViewModel({required super.uiState});

  final counterSelector = _exampleUIStateProvider.select((value) => value.counter);

  void incrementCounter() {
    uiState.update((state) => state.copyWith(counter: state.counter + 1));
  }
}

Constructors

RiverViewModel({required StateController<UISTate> uiState})

Properties

hashCode int
The hash code for this object.
no setterinherited
isBoundLifeCycle bool
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
uiState StateController<UISTate>
Getter returns the StateController used to update the UI state.
no setter

Methods

addComponents(ViewModelLifecycle lifecycleComponent) → void
inherited
markViewModelHasBondLifeCycle() → void
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onApplicationDetached() → void
The application is still hosted on a flutter engine but is detached from any host views.
inherited
onApplicationHidden() → void
The application is still hosted on a flutter engine but is detached from any host views.
inherited
onApplicationInactive() → void
The application is in an inactive state and is not receiving user input.
inherited
onApplicationPaused() → void
The application is not currently visible to the user, not responding to user input, and running in the background.
inherited
onApplicationResumed() → void
The application is visible and responding to user input.
inherited
onDispose() → void
onDispose is called only once when the widget is disposed from the widget tree, to clean up resources such as streams, timers, and tasks that the ViewModel is holding.
inherited
onInitState() → void
onInitState is called only once when the widget has been initialized and inserted into the widget tree, before the build method of the widget is called.
inherited
onPause() → void
onPause is called when the widget is no longer fully displayed in the foreground. onPause will be called in the following cases:
inherited
onResume() → void
onResume is called when the widget is fully displayed in the foreground. onResume will be called in the following cases:
inherited
toString() String
A string representation of this object.
inherited
viewModelScope<G>(Future<G> future(), {Key? key}) Future<G>
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited