ConsumerViewModelWidget<T extends ViewModel> class
abstract
A Widget class that inherits from ConsumerStatefulWidget but wrap HookConsumerWidget so we can use hooks and listen to providers while binding to the corresponding ViewModel.
class ExamplePage extends ConsumerViewModelWidget<ExamplePageViewModel> {
const ExamplePage({super.key});
@override
AutoDisposeProvider<ExamplePageViewModel> viewModelProvider() => exampleViewModelProvider;
@override
Widget buildWidget(BuildContext context, WidgetRef ref, ExamplePageViewModel viewModel) {
final counter = ref.watch(viewModel.counterSelector);
return BuildYourPageWidget();
}
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ConsumerStatefulWidget
- ConsumerViewModelWidget
Constructors
- ConsumerViewModelWidget({Key? key})
-
const
Properties
Methods
-
awake(
WidgetRef ref, T viewModel) → void - The awake method will be called immediately after the createViewModel method of ViewModelWidget and before the onInitState method of the ViewModel. This will be helpful for setting up the necessary data.
-
buildWidget(
BuildContext context, WidgetRef ref, T viewModel) → Widget -
The
build
method is where you build the interface -
createElement(
) → ConsumerStatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → ConsumerState< ConsumerStatefulWidget> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
-
viewModel(
WidgetRef ref) → T - A utility method to get the instance of the existing viewModel provided at viewModelProvider
-
viewModelProvider(
) → AutoDisposeProvider< T> - Provides the current page's ViewModel provider. This provider must be declared in an AutoDisposeProvider to ensure that the ViewModel will be disposed and there will be no memory leaks when the corresponding binding widget is removed from the widget tree.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited