Skip to content
pubscout

ensure_initialized

0.1.0, released 5 years ago by an unverified publisher

Allows to await for an object's heavy initialization before using it.

WASM-ready
$ flutter pub add ensure_initialized
Source repository

What it does

Provides mixins that allow objects to expose an initialization state, handle success and error outcomes, and let consumers await readiness or listen to state changes via streams.

AI-written summary of version 0.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You have objects or services that perform heavy asynchronous initialization and need to be awaited before use.
  • You need to handle reinitialization flows when dependencies change, such as user sign-in and sign-out.

Skip it when

  • You are using a comprehensive dependency injection container that already handles lazy singletons and asynchronous factories out of the box.

Strengths

  • Simple mixin-based API for making any class awaitable until ready
  • Supports initialization results and error propagation
  • Provides streams to listen to initialization and uninitialization events

Weaknesses

  • Manual management of lifecycle states (calling initializedSuccessfully or initializedWithError)
  • Limited built-in orchestration beyond mixin methods

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1
class YourObject with EnsureInitializedMixin {
  Future<void> init() async {
    await Future.delayed(const Duration(seconds: 3));
    initializedSuccessfully();
  }
}

final object = YourObject();
await object.ensureInitialized;
object.doSomethingAfterItIsReady();

Alternatives

Packages that do the same job and could replace ensure_initialized.