ViewState<Page extends View, Con extends Controller> class abstract

The ViewState represents the State of a StatefulWidget, typically of a screen or a page. The ViewState requires a Controller to handle its events and provide its data.

The ViewState also has a default globalKey that can be used inside its build() function in a widget to grant easy access to the Controller, which could then use it to display snackbars, dialogs, and so on.

The ViewState lifecycle is also handled by the Controller.

    class CounterState extends ViewState<CounterPage, CounterController> {
      CounterState(CounterController controller) : super(controller);

      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          home: Scaffold(
            key: globalKey, // using the built-in global key of the `View` for the scaffold or any other
                            // widget provides the controller with a way to access them via getContext(), getState(), getStateKey()
            body: Column(
              children: <Widget>[
                Center(
                  // show the number of times the button has been clicked
                  child: Text(controller.counter.toString()),
                ),
                // you can refresh manually inside the controller
                // using refreshUI()
                MaterialButton(onPressed: controller.increment),
              ],
            ),
          ),
        );
      }
    }

Inheritance
Implementers

Constructors

ViewState(Con _controller)

Properties

builder ViewBuilder
getter/setter pair
context BuildContext
The location in the tree where this widget builds.
no setterinherited
globalKey GlobalKey<State<StatefulWidget>>
final
hashCode int
The hash code for this object.
no setterinherited
mounted bool
Whether this State object is currently in a tree.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
view Widget
Implement the Widget you want to be displayed on View
no setter
widget → Page
The current configuration.
no setterinherited

Methods

activate() → void
Called when this object is reinserted into the tree after having been removed via deactivate.
inherited
build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
deactivate() → void
Called when this object is removed from the tree.
override
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
didChangeDependencies() → void
Called when a dependency of this State object changes.
override
didUpdateWidget(covariant Page oldWidget) → void
Called whenever the widget configuration changes.
inherited
dispose() → void
Called when this object is removed from the tree permanently.
override
initState() → void
Called when this object is inserted into the tree.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reassemble() → void
Called whenever the application is reassembled during debugging, for example during hot reload.
override
setState(VoidCallback fn) → void
Notify the framework that the internal state of this object has changed.
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
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

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