build method
Subclasses should override this function to actually call the appropriate
build function (e.g., StatelessWidget.build or State.build) for
their widget.
Implementation
@override
Widget build() {
// Check whether we can cancel the rebuild (caused by HookState.mayNeedRebuild).
final bool mustRebuild =
(_rebuildRequired ?? true) || _shouldRebuildQueue.any((cb) => cb.value());
_rebuildRequired = null;
_shouldRebuildQueue.clear();
if (!mustRebuild && _buildCache != null) {
return _buildCache!;
}
assert(!(Hook._debugInitializing = false));
_currentEntry = _hooks.firstOrNull;
_current = this;
try {
_buildCache = super.build();
} finally {
_rebuildRequired = null;
_debugDidReassemble = false;
_unmountAllRemainingHooks();
_current = null;
if (_needDispose != null && _needDispose!.isNotEmpty) {
for (
_Entry<Hook<Object?, Object?>>? toDispose = _needDispose!.last;
toDispose != null;
toDispose = toDispose.previous
) {
toDispose.value.dispose();
}
_needDispose = null;
}
}
return _buildCache!;
}