spawn<S> static method

Bind<S> spawn<S>(
  1. InstanceBuilderCallback<S> builder, {
  2. String? tag,
  3. bool permanent = true,
})

Creates a binding and puts the specified dependency into the GetX service locator with a custom lifecycle.

This method is similar to put, but it creates a non-global instance that follows a custom lifecycle management approach.

Parameters:

  • builder: Function that creates the dependency
  • tag: Optional tag for identifying this specific instance
  • permanent: If true, the instance won't be removed on widget disposal

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

Implementation

static Bind<S> spawn<S>(
  InstanceBuilderCallback<S> builder, {
  String? tag,
  bool permanent = true,
}) {
  // Register the dependency with GetX using spawn
  Get.spawn<S>(builder, tag: tag, permanent: permanent);

  // Return a factory binding with appropriate settings
  return _FactoryBind<S>(
    tag: tag,
    global: false, // Spawn creates non-global instances
    autoRemove: !permanent, // Invert permanent to get autoRemove behavior
  );
}