lazyPut<S> method

void lazyPut<S>(
  1. InstanceBuilderCallback<S> builder, {
  2. String? tag,
  3. bool? fenix,
  4. bool permanent = false,
})

Creates a new Instance lazily from the <S>builder() callback.

The first time you call GS.find(), the builder() callback will create the Instance and persisted as a Singleton (like you would use GS.put()).

Using GS.smartManagement as SmartManagement.keepFactory has the same outcome as using fenix:true : The internal register of builder() will remain in memory to recreate the Instance if the Instance has been removed with GS.delete(). Therefore, future calls to GS.find() will return the same Instance.

If you need to make use of GetxController's life-cycle (onInit(), onStart(), onClose()) fenix is a great choice to mix with GetBuilder() and GState() widgets, and/or GetMaterialApp Navigation.

You could use GS.lazyPut(fenix:true) in your app's main() instead of Bindings() for each GetPage. And the memory management will be similar.

Subsequent calls to GS.lazyPut() with the same parameters (<S> and optionally tag will not override the original).

Implementation

void lazyPut<S>(
  InstanceBuilderCallback<S> builder, {
  String? tag,
  bool? fenix,
  bool permanent = false,
}) {
  _insert(
    isSingleton: true,
    name: tag,
    permanent: permanent,
    builder: builder,
    fenix: fenix ?? GS.smartManagement == SmartManagement.keepFactory,
  );
}