Flutter
Flutter lifecycle, errors, and ownership
Understand stable Presenter identity, binding replacement, error routing, and asynchronous teardown inside the widget lifecycle.
Flutter lifecycle, errors, and ownership
MvpView keeps one Presenter while the widget identity and ModelBinding identity remain stable. Ordinary parent rebuilds, Model changes, and inherited Theme or locale changes do not replace it.
A new Presenter is created when
- the resolved ModelBinding instance changes;
- Flutter replaces
MvpViewState, including through a changed key; - the View is removed and inserted later.
The old Presenter is closed asynchronously. Never return a cached Presenter from createPresenter.
Error routing
onError receives asynchronous failures from Model streams, refresh reads, Presenter output channels, subscription cancellation, and closePresenter(). Without a handler, the package reports them through FlutterError.reportError.
Synchronous errors during initial binding, Presenter creation, or ViewState construction remain Flutter build errors. The feature cannot safely continue after partial initialization.
Three ownership domains
- Flutter owns widget
Stateand rendering controllers. MvpViewowns Presenter.- Application composition owns ModelBinding and all captured business objects.
Flutter cannot await dispose(). Presenter cleanup begins immediately and finishes asynchronously, so expensive business resources should remain outside Presenter and be closed by their actual owner.