lazyPut<S> static method

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

Creates a lazy binding and registers a builder function in the GetX service locator.

The dependency will only be created when it's requested for the first time. Use this to defer instantiation until the dependency is actually needed.

Parameters:

  • builder: Function that creates the dependency when needed
  • tag: Optional tag for identifying this specific instance
  • fenix: If true, the instance will be recreated after it's been deleted
  • onClose: Optional callback to run when the instance is removed

Returns a binding widget that can be used in the widget tree.

Implementation

static Bind<S> lazyPut<S>(
  InstanceBuilderCallback<S> builder, {
  String? tag,
  bool fenix = false,
  VoidCallback? onClose,
}) {
  // Register the lazy builder with GetX
  Get.lazyPut<S>(builder, tag: tag, fenix: fenix);

  // Return a factory binding with appropriate settings
  return _FactoryBind<S>(
    tag: tag,
    dispose: switch (onClose) {
      null => null,
      var callback => (_) => callback()
    },
  );
}