buildView property

  1. @protected
void Function() buildView
getter/setter pair

Queues ViewWidget to rebuild.

Typically called when data rendered in ViewWidget changed:

int _counter = 0;
void incrementCounter() {
  _counter++;
  buildView();
}

or used to bind a ViewModel to a ViewWidget:

final counter = ValueNotifier<int>(0);
@override
void initState() {
  super.initState();
  counter.addListener(buildView);
}

Note that buildView is automatically added as a listener to ViewModel, so buildView is called every time notifyListeners is called. However, there is an important distinction between calling notifyListeners and buildView. When this ViewModel is registered, calling notifyListeners will queue ViewWidget to build AND will also notify the listeners of ViewModel of a change, while buildView will not notify other listeners. Therefore, to avoid accidentally notifying listeners, defer to buildView unless listeners need to be notified.

Typically this method is not overridden.

Implementation

@protected
late void Function() buildView = _defaultBuildView;