Recipes

Choose Flutter ownership deliberately

Match Provider construction to the lifecycle boundary that is responsible for closing a UseCase.

v0.1.0-dev.1Intermediateusecase_forge_flutter
Open source reference

Choose Flutter ownership deliberately

The widget that can reach a UseCase is not necessarily the widget that owns its lifecycle. Choose the constructor from the ownership boundary, not from convenience.

Let the provider own a new instance

lib/profile_screen.dart
UseCaseProvider<ProfileUseCase>(
  create: (context) => ProfileUseCase(repository),
  child: const ProfileScreen(),
)

The provider creates the instance once and calls close() when it leaves the tree. Use onCloseError when the application needs explicit handling of asynchronous close failures.

Expose an externally owned instance

lib/profile_screen.dart
UseCaseProvider<ProfileUseCase>.value(
  value: profileUseCase,
  child: const ProfileScreen(),
)

The .value provider never closes the instance. The service, parent scope, or other lifecycle boundary that created it remains responsible.

Dispatch without subscribing to provider identity:

dart
context.readUseCase<ProfileUseCase>().add(const RefreshProfile());

Lookup uses the exact UseCase type. Providing a concrete ProfileUseCase does not register unrelated base types.

ARKTELOS

Purpose-built engineering systems for software that has to hold.