putAsync<S> method

Future<S> putAsync<S>(
  1. AsyncInstanceBuilderCallback<S> builder, {
  2. String? tag,
  3. bool permanent = false,
})

Injects an instance of S built asynchronously by builder into the dependency manager.

Awaits builder and then registers the resulting instance exactly like put, so the regular lifecycle (onInit/onReady) runs on the ready instance. Perform any asynchronous setup inside builder before returning the instance; lifecycle callbacks such as onInit are synchronous and are not awaited.

await Get.putAsync<StorageService>(() async {
  final service = StorageService();
  await service.init();
  return service;
});
  • tag Optional tag to identify this specific instance.
  • permanent If true, prevents the instance from being deleted by SmartManagement.

Implementation

Future<S> putAsync<S>(
  AsyncInstanceBuilderCallback<S> builder, {
  String? tag,
  bool permanent = false,
}) async {
  return put<S>(await builder(), tag: tag, permanent: permanent);
}