Flutter
MvpView and BuildContext
Choose direct or context binding and use Flutter presentation dependencies without retaining stale context.
MvpView and BuildContext
MvpView resolves ModelBinding in a deterministic order:
- use the explicit
modelargument when supplied; - otherwise watch the nearest exact
MvpModelProvider<Model>.
Direct binding
MvpView<ProfileModel, ProfileViewState, ProfileEffect, ProfilePresenter>(
model: profileBinding,
createPresenter: ProfilePresenter.new,
onEffect: handleProfileEffect,
builder: buildProfile,
)
This form keeps a local dependency visible at the feature call site.
Context binding
MvpModelProvider<ProfileModel>.value(
binding: profileBinding,
child: const ProfileScreen(),
)
The descendant omits model. Use context.readMvpModel<ProfileModel>() for a one-off read and context.watchMvpModel<ProfileModel>() when a widget must react to replacement of the binding itself.
Why Presenter receives BuildContext
Flutter localization, themes, accessibility, layout, and inherited presentation settings are context-based. FlutterPresenter.buildViewState(context) may read them synchronously while adapting Model. The runtime never stores context.
Tree-dependent one-time work belongs in onEffect, which receives the currently active context. Presenter methods should accept explicit parameters rather than retaining an old context for later navigation.