### Install Lite Ref Source: https://pub.dev/documentation/lite_ref/latest/index Add the lite_ref package to your Dart or Flutter project using the dart pub add command. This is the first step to integrating Lite Ref into your application. ```bash dart pub add lite_ref ``` -------------------------------- ### Singleton and Transient Instances with Lite Ref Source: https://pub.dev/documentation/lite_ref/latest/index Demonstrates creating global singletons using `Ref.singleton` (ensuring only one instance exists) and transient instances using `Ref.transient` (always creating a new instance). Includes examples for overriding and freezing singletons. ```dart final dbRef = Ref.singleton(() => Database()); assert(dbRef.instance == dbRef.instance); final db = dbRef.instance; // or dbRef() dbRef.overrideWith(() => MockDatabase()); dbRef.freeze(); final dbRefTransient = Ref.transient(() => Database()); assert(dbRefTransient.instance != dbRefTransient.instance); ``` -------------------------------- ### Example Usage of overrideWith Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/ScopedRef/overrideWith Demonstrates how to use the `overrideWith` method within a `LiteRefScope` to provide a mock implementation for a `settingsServiceRef`. ```dart LiteRefScope( overrides: [ settingsServiceRef.overrideWith((ctx) => MockSettingsService()), ], child: MyApp(), ) ``` -------------------------------- ### SingletonRef Class Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/SingletonRef/SingletonRef Provides an overview of the methods available for the SingletonRef class, including methods for calling, freezing, handling no such method errors, overriding, and string representation. ```APIDOC ##### SingletonRef class 1. Constructors 2. new 3. Properties 4. hashCode 5. instance 6. runtimeType 7. Methods 8. call 9. freeze 10. noSuchMethod 11. overrideWith 12. toString 13. Operators 14. operator == ``` -------------------------------- ### Ref Class Constructors and Static Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref/Ref Provides documentation for the Ref class constructor and various static methods used for dependency injection and state management within the lite_ref package. ```APIDOC Ref Class: Constructors: new: Creates a new instance of the Ref class. Static Methods: asyncSingleton(Future Function() create, {String? name, bool autoDispose = false}): Creates an asynchronous singleton. asyncTransient(Future Function() create, {String? name, bool autoDispose = false}): Creates an asynchronous transient. scoped(T Function() create, {String? name, bool autoDispose = false}): Creates a scoped instance. scopedFamily(T Function(Ref ref) create, {String? name, bool autoDispose = false}): Creates a scoped family. singleton(T Function() create, {String? name, bool autoDispose = false}): Creates a singleton instance. transient(T Function() create, {String? name, bool autoDispose = false}): Creates a transient instance. ``` -------------------------------- ### Using ScopedRef.of in a StatelessWidget Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/ScopedRef/of An example demonstrating how to use the `of` method to access a `settingsService` instance within a `SettingsPage` widget and retrieve theme mode information. ```dart class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); @override Widget build(BuildContext context) { final settingsService = settingsServiceRef.of(context); return Text(settingsService.getThemeMode()); } } ``` -------------------------------- ### Ref Class Static Methods for Instance Creation Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref-class Provides an overview of the static methods available on the Ref class for creating various types of refs. These methods allow for asynchronous creation, scoped instances, and family-based instances. ```APIDOC Ref.new() Properties: hashCode → int The hash code for this object. no setter inherited runtimeType → Type A representation of the runtime type of the object. no setter inherited Methods: noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited toString() → String A string representation of this object. inherited Operators: operator ==(Object other) → bool The equality operator. inherited Static Methods: asyncSingleton(Future create()) → AsyncSingletonRef Creates a new AsyncSingletonRef which always return the same instance. asyncTransient(Future create()) → AsyncTransientRef Creates a new AsyncTransientRef which always return a new instance. scoped(CtxCreateFn create, {DisposeFn? dispose, bool autoDispose = true}) → ScopedRef Creates a new ScopedRef which requires a context to access the instance. scopedFamily(CtxFamilyCreateFn create, {DisposeFn? dispose, bool autoDispose = true}) → ScopedFamilyRef Creates a new ScopedFamilyRef which requires a context and family value to access the instance. The family value must be immutable and implement `==` and `hashCode`. singleton(T create()) → SingletonRef Creates a new SingletonRef which always return the same instance. transient(T create()) → TransientRef Creates a new TransientRef which always return a new instance. ``` -------------------------------- ### Creating Refs with Ref Class Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref-class Demonstrates the creation of different types of refs using the Ref class, including scoped, scopedFamily, singleton, and transient instances. These are common patterns for managing dependencies. ```dart final scoped = Ref.scoped((context) => AuthService()); final scopedFamily = Ref.scopedFamily((context, id) => ProductService(id)); final singleton = Ref.singleton(() => Database()); final transient = Ref.transient(() => APIClient()); ``` -------------------------------- ### Automatic Disposal of ScopedRefs Source: https://pub.dev/documentation/lite_ref/latest/index Explains how Lite Ref automatically disposes of instances provided by ScopedRefs if they are ChangeNotifiers, ValueNotifiers, or implement Disposable. The CounterController example shows automatic disposal when CounterView is unmounted. ```dart class CounterController extends ChangeNotifier { var _count = 0; int get count => _count; void increment() { _count++; notifyListeners(); } void decrement() { _count--; notifyListeners(); } } final countControllerRef = Ref.scoped((ctx) => CounterController()); class CounterView extends StatelessWidget { const CounterView({super.key}); @override Widget build(BuildContext context) { final controller = countControllerRef.of(context); return ListenableBuilder( listenable: controller, builder: (context, snapshot) { return Text('${controller.count}'); }, ); } } ``` -------------------------------- ### Asynchronous Singleton with Lite Ref Source: https://pub.dev/documentation/lite_ref/latest/index Shows how to create a singleton instance asynchronously using `Ref.asyncSingleton`. This is useful for services that require initialization, like setting up a database connection. Access the instance using `await dbRef.instance` or synchronously with `dbRef.assertInstance` if the instance is guaranteed to be ready. ```dart final dbRef = Ref.asyncSingleton(() async => await Database.init()); final db = await dbRef.instance; // only use this if you know the instance is already created final db = dbRef.assertInstance; ``` -------------------------------- ### TransientRef Class API - lite_ref Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/TransientRef/TransientRef API documentation for the TransientRef class in the lite_ref package. Lists constructors, properties, methods, and operators available for managing transient instances. ```APIDOC TransientRef Constructors: new TransientRef(T Function() create) - Creates a new TransientRef instance. - Parameters: - create: A function that returns an instance of type T. Properties: hashCode: The hash code for this object. instance: The lazily created instance of type T. runtimeType: A representation of the runtime type of the object. Methods: call(): Invokes the logic to create or retrieve the instance. freeze(): Makes the TransientRef immutable. noSuchMethod(Invocation invocation): Invoked when a non-existent method or property is accessed. overrideWith(T Function() create): Replaces the creation logic with a new function. toString(): A string representation of this object. Operators: operator ==(Object other): Compares this object to another for equality. ``` -------------------------------- ### AsyncSingletonRef Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncSingletonRef-class Lists the methods available for AsyncSingletonRef, including calling the instance, freezing the creation function, handling non-existent methods, overriding the creation function, and converting to a string. ```APIDOC call() → Future Equivalent to calling the instance getter. inherited freeze() → void Disables overriding of the creation function. inherited noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited overrideWith(AsyncFactory create) → Future Sets the function used to create instances. Throws a StateError if `this` has been frozen. override twoString() → String A string representation of this object. inherited ``` -------------------------------- ### ScopedFamilyRef Constructors and Methods - APIDOC Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/ScopedFamilyRef-class Documentation for the ScopedFamilyRef class, covering its constructors, properties, and methods for managing context-dependent instances in the lite_ref package. ```APIDOC ScopedFamilyRef class A ScopedFamilyRef is a reference that needs a context to access instances. Implemented types: * IScopedRef Annotations: * @immutable Constructors: ScopedFamilyRef.new(CtxFamilyCreateFn create, {DisposeFn? dispose, bool autoDispose = true}) Creates a new ScopedFamilyRef which always return new instances. If `autoDispose` is set to `true`, a instance will be disposed when all the widgets that have access to instance are unmounted. Properties: autoDispose → bool Whether the instance should be disposed when all the widgets that have access to the instance are unmounted. final hashCode → int The hash code for this object. no setter override runtimeType → Type A representation of the runtime type of the object. no setter inherited Methods: call(BuildContext context, F family) → T Equivalent to calling the of(context, family) getter. exists(BuildContext context, F family) → bool Returns `true` if this ScopedFamilyRef with that `family` is initialized in the current LiteRefScope. noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited of(BuildContext context, F family, {bool listen = true}) → T Returns the instance of `T` in the current scope for that family. overrideWith(CtxFamilyCreateFn create, {bool autoDispose = true}) → ScopedFamilyRef Returns a new ScopedFamilyRef with a different `create` function. When used with a LiteRefScope overrides, any child widget that accesses the instance will use the new `create` function. read(BuildContext context, F family) → T Returns the instance of `T` in the current scope without disposing it when the widget is unmounted. This should be used in callbacks like `onPressed` or `onTap`. toString() → String A string representation of this object. inherited Operators: operator ==(Object other) → bool The equality operator. override ``` -------------------------------- ### Ref Class Properties and Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref/Ref Details the properties and methods available for the Ref class, including equality checks and string representations. ```APIDOC Ref Class: Properties: hashCode: The hash code for this object. runtimeType: A snapshot of the runtime type of the object. Methods: noSuchMethod(Invocation invocation): Invoked when a non-existent method or property is accessed. toString(): A string representation of this object, for debugging and advertising. Operators: operator ==(Object other): The equality operator. ``` -------------------------------- ### TransientRef Class Documentation Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/TransientRef-class Documentation for the TransientRef class, detailing its constructors, properties, methods, and operators. This class provides a reference that always returns a new instance. ```APIDOC TransientRef class A TransientRef is a reference that always return a new instance. Constructors: TransientRef.new(T create()) Creates a new TransientRef with a given factory function. Properties: hashCode → int The hash code for this object. no setter inherited instance → T Returns a new instance of `T`. no setter runtimeType → Type A representation of the runtime type of the object. no setter inherited Methods: call() → T Equivalent to calling the instance getter. freeze() → void Disables overriding. noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited overrideWith(T create()) → void Sets the function used to create instances. Throws a StateError if `this` has been frozen. toString() → String A string representation of this object. inherited Operators: operator ==(Object other) → bool The equality operator. inherited ``` -------------------------------- ### SingletonRef Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/SingletonRef-class Lists the methods for SingletonRef, including 'call' for instance access and 'overrideWith' for updating the instance creation logic. ```dart call() → T Equivalent to calling the instance getter. ``` ```dart freeze() → void Disables overriding. ``` ```dart noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. ``` ```dart overrideWith(T create()) → void Sets the function used to create instances. Throws a StateError if `this` has been frozen. ``` ```dart toString() → String A string representation of this object. ``` -------------------------------- ### AsyncSingletonRef Class Members - Dart Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncSingletonRef/AsyncSingletonRef Lists the constructors, properties, and methods available for the AsyncSingletonRef class in the lite_ref package. ```APIDOC AsyncSingletonRef class Constructors: new Properties: assertInstance hashCode hasInstance instance runtimeType Methods: call freeze noSuchMethod overrideWith toString Operators: operator == ``` -------------------------------- ### Create AsyncSingletonRef Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref/asyncSingleton Creates a new AsyncSingletonRef which always returns the same instance. It takes a Future-returning function to create the instance. ```dart static AsyncSingletonRef asyncSingleton( Future Function() create, ) { return AsyncSingletonRef(create); } ``` -------------------------------- ### LiteRefScope Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/LiteRefScope-class Documents the methods available for the LiteRefScope class, including those for element creation, debugging, and updating notification. ```APIDOC Methods: createElement() → InheritedElement Inflates this configuration to a concrete instance. override debugDescribeChildren() → List Returns a list of DiagnosticsNode objects describing this node's children. inherited debugFillProperties(DiagnosticPropertiesBuilder properties) → void Add additional properties associated with the node. inherited noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited toDiagnosticsNode({String? name, DiagnosticTreeStyle? style}) → DiagnosticsNode Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. inherited tostring({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String A string representation of this object. inherited tostringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String Returns a string representation of this node and its descendants. inherited tostringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String Returns a one-line detailed description of the object. inherited tostringShort() → String A short, textual description of this widget. inherited updateShouldNotify(covariant InheritedWidget oldWidget) → bool Whether the framework should notify widgets that inherit from this widget. override ``` -------------------------------- ### ScopedRef Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/ScopedRef-class Explains the various methods available for the ScopedRef class, such as accessing instances, checking existence, and overriding creation logic. ```APIDOC call(BuildContext context) → T Equivalent to calling the of(context) getter. exists(BuildContext context) → bool Returns `true` if this ScopedRef is initialized in the current LiteRefScope. noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited of(BuildContext context, {bool listen = true}) → T Returns the instance of `T` in the current scope. overrideWith(CtxCreateFn create, {bool autoDispose = true}) → ScopedRef Returns a new ScopedRef with a different `create` function. When used with a LiteRefScope overrides, any child widget that accesses the instance will use the new `create` function. read(BuildContext context) → T Returns the instance of `T` in the current scope without disposing it when the widget is unmounted. This should be used in callbacks like `onPressed` or `onTap`. tosString() → String A string representation of this object. inherited ``` -------------------------------- ### Using ScopedRef with LiteRefScope Source: https://pub.dev/documentation/lite_ref/latest/index Demonstrates how to use ScopedRef for instances that require a BuildContext. Wrap your app with LiteRefScope and create ScopedRefs for services like SettingsService. Access instances using .of(context) or by calling the ref directly. ```dart runApp( LiteRefScope( child: MyApp(), ), ); final settingsServiceRef = Ref.scoped((ctx) => SettingsService()); class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); @override Widget build(BuildContext context) { final settingsService = settingsServiceRef.of(context); return Text(settingsService.getThemeMode()); } } ``` -------------------------------- ### AsyncSingletonRef Constructors Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncSingletonRef-class Defines the constructor for creating an AsyncSingletonRef instance. It takes an AsyncFactory as a parameter to specify the creation function. ```APIDOC AsyncSingletonRef.new(AsyncFactory create) Creates a new AsyncSingletonRef with the given asynchronous factory function. ``` -------------------------------- ### LiteRefScope createElement Implementation Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/LiteRefScope/createElement The createElement method is overridden to return a new instance of _RefScopeElement, which is responsible for inflating the LiteRefScope configuration into the element tree. ```dart @override InheritedElement createElement() => _RefScopeElement(this); ``` -------------------------------- ### Ref Abstract Class Source: https://pub.dev/documentation/lite_ref/latest/lite_ref An abstract base class for creating references. ```dart Ref ``` -------------------------------- ### AsyncTransientRef Constructor - Dart Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncTransientRef/AsyncTransientRef The constructor for AsyncTransientRef takes an AsyncFactory to create instances asynchronously. It initializes the internal create function. ```dart AsyncTransientRef constructor AsyncTransientRef( 1. AsyncFactory create ) Implementation: AsyncTransientRef(AsyncFactory create) : _create = create; ``` -------------------------------- ### AsyncTransientRef Class Overview Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncTransientRef-class Provides details on the AsyncTransientRef class, its purpose, constructors, properties, methods, and operators within the lite_ref package. ```APIDOC AsyncTransientRef class A AsyncTransientRef is a reference with an asynchronous factory/creation function that always return a new instance. Constructors: AsyncTransientRef.new(AsyncFactory create) Properties: hashCode → int The hash code for this object. instance → Future Returns a new instance of `T`. runtimeType → Type A representation of the runtime type of the object. Methods: call() → Future Equivalent to calling the instance getter. freeze() → void Disables overriding of the creation function. noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. overrideWith(AsyncFactory create) → void Sets the function used to create instances. Throws a StateError if `this` has been frozen. toString() → String A string representation of this object. Operators: operator ==(Object other) → bool The equality operator. ``` -------------------------------- ### Using ScopedFamilyRef for Keyed Instances Source: https://pub.dev/documentation/lite_ref/latest/index Illustrates the use of ScopedFamilyRef to create unique instances based on keys. This is helpful for managing multiple instances of the same class, such as PostController instances identified by unique keys. ```dart final postControllerRef = Ref.scopedFamily((ctx, String key) { return PostController(key)..fetch(); }); class PostsPage extends StatelessWidget { const PostsPage({required this.keys, super.key}); final List keys; @override Widget build(BuildContext context) { return ListView.builder( itemBuilder: (context, index) { final post = postControllerRef.of(context, keys[index]); return Text(post?.title ?? 'Loading...'); }, ); } } ``` -------------------------------- ### ScopedRef Constructors and Properties Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/ScopedRef-class Details the constructors and properties of the ScopedRef class, including how to create a new ScopedRef and manage its auto-disposal behavior. ```APIDOC ScopedRef.new(CtxCreateFn create, {DisposeFn? dispose, bool autoDispose = true}) Creates a new ScopedRef which always return a new instance. If `autoDispose` is set to `true`, the instance will be disposed when all the widgets that have access to the instance are unmounted. autoDispose → bool Whether the instance should be disposed when all the widgets that have access to the instance are unmounted. final hashCode → int The hash code for this object. no setteroverride runtimeType → Type A representation of the runtime type of the object. no setterinherited ``` -------------------------------- ### LiteRefScope Class Source: https://pub.dev/documentation/lite_ref/latest/lite_ref Manages dependency injection for ScopedRefs. ```dart LiteRefScope ``` -------------------------------- ### Singleton Ref Creation (Dart) Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref/singleton Creates a new SingletonRef which always returns the same instance. This is a static method within the Ref class. ```dart static SingletonRef singleton(T Function() create) { return SingletonRef(create); } ``` -------------------------------- ### AsyncSingletonRef Constructor - Dart Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncSingletonRef/AsyncSingletonRef The constructor for AsyncSingletonRef in Dart. It takes an AsyncFactory to create the instance. ```dart AsyncSingletonRef constructor AsyncSingletonRef( AsyncFactory create ) Implementation: AsyncSingletonRef(super.create); ``` -------------------------------- ### SingletonRef Properties Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/SingletonRef-class Details the properties available for SingletonRef, including 'instance' for accessing the singleton object. ```dart get instance → T Returns the singleton instance of `T`. ``` ```dart get hashCode → int The hash code for this object. ``` ```dart get runtimeType → Type A representation of the runtime type of the object. ``` -------------------------------- ### SingletonRef Constructor Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/SingletonRef/SingletonRef The constructor for SingletonRef takes a factory function `create` which is responsible for creating the singleton instance of type T. The implementation simply calls the superclass constructor with this factory function. ```dart SingletonRef( T create() ) // Implementation SingletonRef(super.create); ``` -------------------------------- ### AsyncSingletonRef Class Source: https://pub.dev/documentation/lite_ref/latest/lite_ref Represents a reference with an asynchronous factory that always returns the same instance. ```dart AsyncSingletonRef ``` -------------------------------- ### Create and Use ScopedRef Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref/scoped Demonstrates how to create a `ScopedRef` for a service and access its instance within a widget. It also shows how to wrap the application with `LiteRefScope` to provide the necessary context. ```dart final settingsServiceRef = Ref.scoped((ctx) => SettingsService()); class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); @override Widget build(BuildContext context) { final settingsService = settingsServiceRef.of(context); return Text(settingsService.getThemeMode()); } } ``` -------------------------------- ### AsyncSingletonRef Properties Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncSingletonRef-class Details the properties available for AsyncSingletonRef instances, including accessing the instance, its hash code, whether an instance exists, and its runtime type. ```APIDOC assertInstance → T Returns instance if it has been created. Otherwise, it throws a StateError. no setter hashCode → int The hash code for this object. no setterinherited hasInstance → bool Returns `true` if the instance has been created. no setter instance → Future Returns a the singleton instance of `T`. no setteroverride runtimeType → Type A representation of the runtime type of the object. no setterinherited ``` -------------------------------- ### SingletonRef Constructors Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/SingletonRef-class Defines the constructor for SingletonRef, which takes a factory function to create new instances. ```dart SingletonRef.new(T create()) ``` -------------------------------- ### SingletonRef Class Source: https://pub.dev/documentation/lite_ref/latest/lite_ref A reference that always returns the same instance. ```dart SingletonRef ``` -------------------------------- ### LiteRefScope Constructor and Properties Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/LiteRefScope-class Details the constructor for LiteRefScope, which allows for dependency injection of ScopedRefs, and lists its key properties such as child, key, onlyOverrides, and overrides. ```APIDOC LiteRefScope.new({required Widget child, Key? key, Set? overrides, bool onlyOverrides = false}) Create a new LiteRefScope If `onlyOverrides` is true, only overridden ScopedRefs will be provided to children. Properties: child → Widget The widget below this widget in the tree. finalinherited hashCode → int The hash code for this object. no setterinherited key → Key? Controls how one widget replaces another widget in the tree. finalinherited onlyOverrides → bool If true, only overridden ScopedRefs will be provided to children. final overrides → Set? List of ScopedRefs to override. final runtimeType → Type A representation of the runtime type of the object. no setterinherited ``` -------------------------------- ### Ref Class Static Methods Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref/scopedFamily Lists the static methods available on the `Ref` class within the lite_ref package, including `asyncSingleton`, `asyncTransient`, `scoped`, `scopedFamily`, `singleton`, and `transient`. ```APIDOC Ref class static methods: asyncSingleton asyncTransient scoped scopedFamily singleton transient ``` -------------------------------- ### IScopedRef Class Documentation Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/IScopedRef-class Documentation for the IScopedRef class, a sealed interface requiring context for instance access. It details properties like autoDispose, hashCode, and runtimeType, and methods such as noSuchMethod and toString. ```APIDOC IScopedRef class sealed A ScopedRef is a reference that needs a context to access the instance. Implementers: * ScopedFamilyRef * ScopedRef ## Properties autoDispose → bool Whether the instance should be disposed when all the widgets that have access to the instance are unmounted. no setter hashCode → int The hash code for this object. no setterinherited runtimeType → Type A representation of the runtime type of the object. no setterinherited ## Methods noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited tostring() → String A string representation of this object. inherited ## Operators operator ==(Object other) → bool The equality operator. inherited ``` -------------------------------- ### AsyncTransientRef.instance getter Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncTransientRef/instance Returns a new instance of `T` from the AsyncTransientRef class. ```dart Future get instance => _create(); ``` -------------------------------- ### IScopedRef Interface Source: https://pub.dev/documentation/lite_ref/latest/lite_ref An interface for references that require a context to access their instances. ```dart IScopedRef ``` -------------------------------- ### AsyncTransientRef Class Source: https://pub.dev/documentation/lite_ref/latest/lite_ref Represents a reference with an asynchronous factory that always returns a new instance. ```dart AsyncTransientRef ``` -------------------------------- ### Disposable Class API Documentation Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Disposable-class API documentation for the abstract Disposable class in the lite_ref package. This class serves as a contract for managing resource disposal, ensuring that classes implementing it properly release resources like file handles, database connections, or subscriptions to prevent memory leaks. ```APIDOC Disposable class abstract mixin An abstract class that provides a contract for disposing resources. Classes that implement/mixin `Disposable` should override the `dispose` method to release or cleanup resources such as file handles, database connections, subscriptions, etc. This is crucial for preventing resource leaks in applications. ## Constructors Disposable.new() ## Properties hashCode → int The hash code for this object. no setterinherited runtimeType → Type A representation of the runtime type of the object. no setterinherited ## Methods dispose() → void Releases or cleans up resources used by the object. noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited tostring() → String A string representation of this object. inherited ## Operators operator ==(Object other) → bool The equality operator. inherited ``` -------------------------------- ### AsyncSingletonRef assertInstance Property Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/AsyncSingletonRef/assertInstance The assertInstance property returns the singleton instance if it has already been created. If the instance has not been created yet, it throws a StateError, indicating that the `instance` method must be called and awaited first. ```dart T get assertInstance { if (hasInstance) return _instance as T; throw StateError( 'The instance has not been created yet. ' 'You must call `instance` first and await it.', ); } ``` -------------------------------- ### CtxCreateFn Typedef Source: https://pub.dev/documentation/lite_ref/latest/lite_ref Defines the function signature for creating an instance of type T using a BuildContext. ```dart CtxCreateFn = T Function(BuildContext context) ``` -------------------------------- ### Create and Use ScopedFamilyRef Source: https://pub.dev/documentation/lite_ref/latest/lite_ref/Ref/scopedFamily Demonstrates how to create a `ScopedFamilyRef` using `Ref.scopedFamily` and access its instance within a widget. It shows the typical pattern for state management in Flutter applications using the lite_ref package. ```flutter runApp( LiteRefScope( child: MyApp(), ), ); final productControllerRef = Ref.scopedFamily((BuildContext context, int id) => ProductController(id: id)); class ProductWidget extends StatelessWidget { const SettingsPage({required this.id, super.key}); final int id; @override Widget build(BuildContext context) { final productController = productControllerRef.of(context, id); return Text(productController.getName()); } } ``` -------------------------------- ### Disposable Class Source: https://pub.dev/documentation/lite_ref/latest/lite_ref An abstract class defining a contract for disposing resources. ```dart Disposable ```