createState method
Builds the state than manages this ViewWidget
This functions is already defined for this ViewWidget class so typically doesn't need to be overridden. An exception is when you need to add a mixin to the state class. To add a mixin, extend ViewState<ViewWidget
class MyWidget extends ViewWidget
// Overriding createState is only required when adding mixins
@override
MyWidgetState createState() => MyWidgetState();
@override
Widget build(BuildContext context) {
// Use `getState` to retrieve your custom ViewState/mixin object
return getState<MyWidgetState>().buildGreeting(viewModel.message.value);
}
}
// Extend ViewState
and add your mixin
class MyWidgetState extends ViewState
mixin MyMixin { buildGreeting(String message) => Text(message); }
class MyWidgetViewModel extends ViewModel { late final message = createProperty
Implementation
@override
State<ViewWidget<T>> createState() => ViewState<T>();