Reactter provides several methods to manage dependencies in a more efficient way.
These methods are used to create and manipulate dependencies in a more organized way.
Rt . register
The Rt . register
method registers a new dependency.
It returns true
if the dependency is registered successfully, otherwise return false
.
Syntax
DependencyMode mode = DependencyMode . builder ,
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the dependency is registered by its type( T
).
mode
: The mode of the dependency. It can be DependencyMode . builder
, DependencyMode . factory
, or DependencyMode . singleton
.
The default value is DependencyMode . builder
. Learn more about it in DependencyMode .
Example
See the example below to understand how to use the Rt . register
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
Rt . register < Counter >(() => Counter ()) ;
final counter = Rt . get < Counter >() ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Error: "Can't update when it's been disposed", because the dependency instance was deleted
// Can't get the dependency instance, because the dependency register was deleted
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ; // counter2: null
// Register a dependency using `id` parameter
Rt . register (() => Counter () , id : 'CounterById' ) ;
// Get the dependency using `id` parameter
final counterById = Rt . get < Counter >( 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency using `id` parameter
Rt . delete < Counter >( 'CounterById' ) ;
// Register a dependency using `mode` parameter as singleton mode
Rt . register (() => Counter () , mode : DependencyMode . singleton) ;
final counterBySingletonMode = Rt . get < Counter >() ;
print ( "counterBySingletonMode: ${ counterBySingletonMode ?. hashCode } " ) ;
// Can get the dependency again, because it's singleton mode
final counterBySingletonMode2 = Rt . get < Counter >() ;
"counterBySingletonMode2: ${ counterBySingletonMode2 ?. hashCode } " ,
// Use `onlyInstance` parameter to delete the dependency instance only
Rt . destroy < Counter >(onlyInstance : true ) ;
// Can't get the dependency instance, because the dependency register was destroyed
final counterBySingletonMode3 = Rt . find < Counter >() ;
"counterBySingletonMode3: ${ counterBySingletonMode3 ?. hashCode } " ,
) ; // counterBySingletonMode3: null
// If you need to delete the dependency fully, use ` Rt.destroy ` method by forcing it, because it's singleton mode
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . lazyBuilder
The Rt . lazyBuilder
method registers a new dependency as DependencyMode . builder
.
It returns true
if the dependency is registered successfully, otherwise return false
.
This method is similar to the Rt . register
method but with the DependencyMode . builder
mode only.
Syntax
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the dependency is registered by its type( T
).
Example
See the example below to understand how to use the Rt . lazyBuilder
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Register a dependency as builder mode.
Rt . lazyBuilder < Counter >(() => Counter ()) ;
final counter = Rt . get < Counter >() ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Error: "Can't update when it's been disposed", because the dependency instance was deleted
// Can't get the dependency instance, because the dependency register was deleted
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ; // counter2: null
// Register a dependency using `id` parameter as builder mode
Rt . lazyBuilder (() => Counter () , id : 'CounterById' ) ;
// Get the dependency using `id` parameter
final counterById = Rt . get < Counter >( 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency using `id` parameter
Rt . delete < Counter >( 'CounterById' ) ;
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . lazyFactory
The Rt . lazyFactory
method registers a new dependency as DependencyMode . factory
.
It returns true
if the dependency is registered successfully, otherwise return false
.
This method is similar to the Rt . register
method but with the DependencyMode . factory
mode only.
Syntax
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the dependency is registered by its type( T
).
Example
See the example below to understand how to use the Rt . lazyFactory
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Register a dependency as factory mode.
Rt . lazyFactory < Counter >(() => Counter ()) ;
final counter = Rt . get < Counter >() ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Error: "Can't update when it's been disposed", because the dependency instance was deleted
// Can get the dependency instance, but it's created again, because it's factory mode
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ;
// Delete the dependency instance and its register
// Can't get the dependency instance, because the dependency register was deleted using `destroy` method
final counter3 = Rt . get < Counter >() ;
print ( "counter3: ${ counter3 ?. hashCode } " ) ; // counter3: null
// Register a dependency using `id` parameter as factory mode
Rt . lazyFactory (() => Counter () , id : 'CounterById' ) ;
// Get the dependency using `id` parameter
final counterById = Rt . get < Counter >( 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency instance and its register using `id` parameter
Rt . destroy < Counter >(id : 'CounterById' ) ;
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . lazySingleton
The Rt . lazySingleton
method registers a new dependency as DependencyMode . singleton
.
It returns true
if the dependency is registered successfully, otherwise return false
.
This method is similar to the Rt . register
method but with the DependencyMode . singleton
mode.
Syntax
bool Rt . lazySingleton < T >(
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the dependency is registered by its type( T
).
Example
See the example below to understand how to use the Rt . lazySingleton
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Register a dependency as singleton mode.
Rt . lazySingleton < Counter >(() => Counter ()) ;
final counter = Rt . get < Counter >() ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Can't delete the dependency, because it's singleton mode
// Can update the state, because it's singleton mode
// Can get the same dependency instanse, because it's singleton mode
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ;
// Delete the dependency instance
Rt . destroy < Counter >(onlyInstance : true ) ;
// Can get the dependency instance, but it's created again, because it's singleton mode
final counter3 = Rt . get < Counter >() ;
print ( "counter3: ${ counter3 ?. hashCode } " ) ;
// Delete the dependency instance and its register
// Can't get the dependency instance, because the dependency register was deleted using `destroy` method
final counter4 = Rt . get < Counter >() ;
print ( "counter4: ${ counter4 ?. hashCode } " ) ; // counter4: null
// Register a dependency using `id` parameter as singleton mode
Rt . lazySingleton (() => Counter () , id : 'CounterById' ) ;
// Get the dependency using `id` parameter
final counterById = Rt . get < Counter >( 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency instance and its register using `id` parameter
Rt . destroy < Counter >(id : 'CounterById' ) ;
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . create
The Rt . create
method registers a dependency(if not already registered), create its instance(if not created yet) and return it.
Syntax
T Rt . create < T >( T Function () builder , {
DependencyMode mode = DependencyMode . builder ,
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . create
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
final counter = Rt . create < Counter >(() => Counter ()) ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Error: "Can't update when it's been disposed", because the dependency instance was deleted
// Can't get the dependency instance, because the dependency register was deleted
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ; // counter2: null
// Create a dependency using `id` parameter
final counterById = Rt . create (() => Counter () , id : 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency using `id` parameter
Rt . delete < Counter >( 'CounterById' ) ;
// Create a dependency using `mode` parameter as singleton mode
final counterBySingletonMode = Rt . create (
mode : DependencyMode . singleton ,
print ( "counterBySingletonMode: ${ counterBySingletonMode ?. hashCode } " ) ;
// Can get the dependency again, because it's singleton mode
final counterBySingletonMode2 = Rt . get < Counter >() ;
"counterBySingletonMode2: ${ counterBySingletonMode2 ?. hashCode } " ,
// Use `onlyInstance` parameter to delete the dependency instance only
Rt . destroy < Counter >(onlyInstance : true ) ;
// Can't get the dependency instance, because the dependency register was destroyed
final counterBySingletonMode3 = Rt . find < Counter >() ;
"counterBySingletonMode3: ${ counterBySingletonMode3 ?. hashCode } " ,
) ; // counterBySingletonMode3: null
// If you need to delete the dependency fully, use ` Rt.destroy ` method by forcing it, because it's singleton mode
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . builder
The Rt . create
method registers a dependency as DependencyMode . builder
(if not already registered), create its instance(if not created yet) and return it.
This method is similar to the Rt . create
method.
Syntax
T Rt . builder < T >( T Function () builder , {
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . builder
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create a dependency as builder mode.
final counter = Rt . builder < Counter >(() => Counter ()) ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Error: "Can't update when it's been disposed", because the dependency instance was deleted
// Can't get the dependency instance, because the dependency register was deleted
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ; // counter2: null
// Create a dependency using `id` parameter as builder mode
final counterById = Rt . builder < Counter >(
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency using `id` parameter
Rt . delete < Counter >( 'CounterById' ) ;
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . factory
The Rt . factory
method registers a dependency as DependencyMode . factory
(if not already registered), create its instance(if not created yet) and return it.
This method is similar to the Rt . create
method but with the DependencyMode . factory
mode.
Syntax
T Rt . factory< T > ( T Function () builder , {
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . factory
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create a dependency as factory mode.
final counter = Rt . factory < Counter > (() => Counter ()) ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Error: "Can't update when it's been disposed", because the dependency instance was deleted
// Can get the dependency instance, but it's created again, because it's factory mode
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ;
// Delete the dependency instance and its register
// Can't get the dependency instance, because the dependency register was deleted using `destroy` method
final counter3 = Rt . get < Counter >() ;
print ( "counter3: ${ counter3 ?. hashCode } " ) ; // counter3: null
// Create a dependency using `id` parameter as factory mode
final counterById = Rt . factory (() => Counter () , id : 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency instance and its register using `id` parameter
Rt . destroy < Counter >(id : 'CounterById' ) ;
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . singleton
The Rt . singleton
method registers a dependency as DependencyMode . singleton
(if not already registered), create its instance(if not created yet) and return it.
This method is similar to the Rt . create
method but with the DependencyMode . singleton
mode.
Syntax
T Rt . singleton < T >( T Function () builder , {
Parameters
builder
: A function that returns an instance of the T
dependency.
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . singleton
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create a dependency as singleton mode.
final counter = Rt . singleton < Counter >(() => Counter ()) ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Listen to the state changes
print ( "Count: ${ counter . count . value } " ) ;
// Can't delete the dependency, because it's singleton mode
// Can update the state, because it's singleton mode
// Can get the same dependency instanse, because it's singleton mode
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ;
// Delete the dependency instance
Rt . destroy < Counter >(onlyInstance : true ) ;
// Can get the dependency instance, but it's created again, because it's singleton mode
final counter3 = Rt . get < Counter >() ;
print ( "counter3: ${ counter3 ?. hashCode } " ) ;
// Delete the dependency instance and its register
// Can't get the dependency instance, because the dependency register was deleted using `destroy` method
final counter4 = Rt . get < Counter >() ;
print ( "counter4: ${ counter4 ?. hashCode } " ) ; // counter4: null
// Create a dependency using `id` parameter as singleton mode
final counterById = Rt . singleton (() => Counter () , id : 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency instance and its register using `id` parameter
Rt . destroy < Counter >(id : 'CounterById' ) ;
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . get
The Rt . get
method creates the dependency instance(if not created yet), retrieves it, and then return it.
If the dependency is not created, it will return null
.
Syntax
T ? Rt . get < T >([ String ? id]) ;
Parameters
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . get
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
Rt . register < Counter >(() => Counter ()) ;
final counter = Rt . get < Counter >() ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Can't get the dependency instance, because the dependency register was deleted
final counter2 = Rt . get < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ; // counter2: null
Rt . register < Counter >(() => Counter () , id : 'CounterById' ) ;
// Get the dependency using `id` parameter
final counterById = Rt . get < Counter >( 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency using `id` parameter
Rt . delete < Counter >( 'CounterById' ) ;
// Can't get the dependency instance using `id` parameter, because the dependency register was deleted
final counterById2 = Rt . get < Counter >( 'CounterById' ) ;
print ( "counterById2: ${ counterById2 ?. hashCode } " ) ; // counter2: null
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . find
The Rt . find
method retrieves the created dependency instance and returns it. If the dependency is not created, returns null
.
Syntax
T ? Rt . find < T >([ String ? id]) ;
Parameters
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . find
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
Rt . create < Counter >(() => Counter ()) ;
final counter = Rt . find < Counter >() ;
print ( "counter: ${ counter ?. hashCode } " ) ;
// Can't find the dependency instance, because the dependency register was deleted
final counter2 = Rt . find < Counter >() ;
print ( "counter2: ${ counter2 ?. hashCode } " ) ; // counter2: null
Rt . create < Counter >(() => Counter () , id : 'CounterById' ) ;
// Find the dependency using `id` parameter
final counterById = Rt . find < Counter >( 'CounterById' ) ;
print ( "counterById: ${ counterById ?. hashCode } " ) ;
// Delete the dependency using `id` parameter
Rt . delete < Counter >( 'CounterById' ) ;
// Can't find the dependency instance using `id` parameter, because the dependency register was deleted
final counterById2 = Rt . find < Counter >( 'CounterById' ) ;
print ( "counterById2: ${ counterById2 ?. hashCode } " ) ; // counter2: null
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . exists
The Rt . exists
method checks if the dependency instance exists in Reactter. It returns true
if the dependency exists, otherwise return false
.
Syntax
bool Rt . exists < T >([ String ? id]) ;
Parameters
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . exists
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
Rt . create < Counter >(() => Counter ()) ;
// Check if the dependency exists
final isExists = Rt . exists < Counter >() ;
print ( "Counter exists: $ isExists " ) ; // Counter exists: true
// Check if the dependency exists after deleting it
final isExists2 = Rt . exists < Counter >() ;
"Counter exists after deleting: $ isExists2 " ,
) ; // Counter exists after deleting: false
// Create a dependency using `id` parameter
Rt . create < Counter >(() => Counter () , id : 'CounterById' ) ;
// Check if the dependency exists using `id` parameter
final isExistsById = Rt . exists < Counter >( 'CounterById' ) ;
print ( "Counter by id exists: $ isExistsById " ) ; // Counter by id exists: true
// Delete the dependency using `id` parameter
Rt . delete < Counter >( 'CounterById' ) ;
// Check if the dependency exists after deleting it using `id` parameter
final isExistsById2 = Rt . exists < Counter >( 'CounterById' ) ;
"Counter by id exists after deleting: $ isExistsById2 " ,
) ; // Counter by id exists after deleting: false
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . getDependencyMode
The Rt . getDependencyMode
method retrieves the dependency mode of a registered dependency. If the dependency is not registered, it returns null
.
Syntax
DependencyMode ? Rt . getDependencyMode < T >([ String ? id]) ;
Parameters
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . getDependencyMode
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create the dependencies with different dependency modes
final counter = Counter () ;
final counter2 = Rt . builder < Counter >(() => Counter () , id : 'Builder' ) ;
final counter3 = Rt . factory < Counter > (() => Counter () , id : 'Factory' ) ;
final counter4 = Rt . singleton < Counter >(
// Check the dependency modes
final counterMode = Rt . getDependencyMode (counter) ;
final counter2Mode = Rt . getDependencyMode (counter2) ;
final counter3Mode = Rt . getDependencyMode (counter3) ;
final counter4Mode = Rt . getDependencyMode (counter4) ;
'Counter mode: $ counterMode ' ,
'Counter2 mode: $ counter2Mode ' ,
) ; // Counter2 mode: DependencyMode.builder
'Counter3 mode: $ counter3Mode ' ,
) ; // Counter3 mode: DependencyMode.factory
'Counter4 mode: $ counter4Mode ' ,
) ; // Counter4 mode: DependencyMode.singleton
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . delete
The Rt . delete
method removes the dependency instance and its registration from the Reactter based on the dependency mode.
It returns true
if the dependency is successfully deleted, otherwise return false
.
Note
The behavior of the Rt . delete
method depends on the dependency mode:
If the dependency is registered as Builder mode, both the dependency instance and its registration will be deleted.
If the dependency is registered as Factory mode, only the dependency instance will be deleted, but its registration remains.
If the dependency is registered as Singleton mode, nothing will be deleted.
For more information about the dependency modes, refer to Dependency Modes .
Syntax
bool Rt . delete < T >([ String ? id]) ;
Parameters
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
Example
See the example below to understand how to use the Rt . delete
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create the dependencies with different dependency modes
final counter = Rt . create < Counter >(() => Counter ()) ;
final counter2 = Rt . builder < Counter >(() => Counter () , id : 'Builder' ) ;
final counter3 = Rt . factory < Counter > (() => Counter () , id : 'Factory' ) ;
final counter4 = Rt . singleton < Counter >(
// Delete the dependencies
final isDeleted = Rt . delete < Counter >() ;
final isDeleted2 = Rt . delete < Counter >( 'Builder' ) ;
final isDeleted3 = Rt . delete < Counter >( 'Factory' ) ;
final isDeleted4 = Rt . delete < Counter >( 'Singleton' ) ;
// Print if the dependencies are deleted
print ( 'isDeleted: $ isDeleted ' ) ; // isDeleted: true
print ( 'isDeleted2: $ isDeleted2 ' ) ; // isDeleted2: true
print ( 'isDeleted3: $ isDeleted3 ' ) ; // isDeleted3: true
print ( 'isDeleted4: $ isDeleted4 ' ) ; // isDeleted4: false
final counterAfterDeleted = Rt . get < Counter >() ;
final counterAfterDeleted2 = Rt . get < Counter >( 'Builder' ) ;
final counterAfterDeleted3 = Rt . get < Counter >( 'Factory' ) ;
final counterAfterDeleted4 = Rt . get < Counter >( 'Singleton' ) ;
// Check if the dependencies are obtained
final isObtained = counterAfterDeleted != null ;
final isObtained2 = counterAfterDeleted2 != null ;
final isObtained3 = counterAfterDeleted3 != null ;
final isObtained4 = counterAfterDeleted4 != null ;
// Print if the dependencies are obtained
print ( 'isObtained: $ isObtained ' ) ; // isObtained: false
print ( 'isObtained2: $ isObtained2 ' ) ; // isObtained2: false
print ( 'isObtained3: $ isObtained3 ' ) ; // isObtained3: true
print ( 'isObtained4: $ isObtained4 ' ) ; // isObtained4: true
// Check if the dependencies are the same instance
final isSameInstance = counter == counterAfterDeleted ;
final isSameInstance2 = counter2 == counterAfterDeleted2 ;
final isSameInstance3 = counter3 == counterAfterDeleted3 ;
final isSameInstance4 = counter4 == counterAfterDeleted4 ;
// Print if the dependencies are the same instance
print ( 'isSameInstance: $ isSameInstance ' ) ; // isSameInstance: false
print ( 'isSameInstance2: $ isSameInstance2 ' ) ; // isSameInstance2: false
print ( 'isSameInstance3: $ isSameInstance3 ' ) ; // isSameInstance3: false
print ( 'isSameInstance4: $ isSameInstance4 ' ) ; // isSameInstance4: true
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . destroy
The Rt . destroy
method forcibly removes the dependency instance and its registration from the Reactter.
It returns true
if the dependency is successfully destroyed, otherwise return false
.
Syntax
bool onlyDependency = false ,
Parameters
id
: An optional identifier for the T
dependency. If not provided, the default instance of the T
dependency is used.
onlyDependency
: An optional parameter to delete the dependency instance only. The default value is false
.
Example
See the example below to understand how to use the Rt . destroy
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create the dependencies with different dependency modes
Rt . create < Counter >(() => Counter ()) ;
Rt . builder < Counter >(() => Counter () , id : 'Builder' ) ;
Rt . factory < Counter > (() => Counter () , id : 'Factory' ) ;
Rt . singleton < Counter >(() => Counter () , id : 'Singleton' ) ;
// Delete the dependencies
final isDestroyed = Rt . destroy < Counter >(onlyInstance : true ) ;
final isDestroyed2 = Rt . destroy < Counter >(id : 'Builder' ) ;
final isDestroyed3 = Rt . destroy < Counter >(id : 'Factory' ) ;
final isDestroyed4 = Rt . destroy < Counter >(id : 'Singleton' ) ;
// Print if the dependencies are destroyed
print ( 'isDestroyed: $ isDestroyed ' ) ; // isDestroyed: false
print ( 'isDestroyed2: $ isDestroyed2 ' ) ; // isDestroyed2: true
print ( 'isDestroyed3: $ isDestroyed3 ' ) ; // isDestroyed3: true
print ( 'isDestroyed4: $ isDestroyed4 ' ) ; // isDestroyed4: true
final counterAfterDeleted = Rt . get < Counter >() ;
final counterAfterDeleted2 = Rt . get < Counter >( 'Builder' ) ;
final counterAfterDeleted3 = Rt . get < Counter >( 'Factory' ) ;
final counterAfterDeleted4 = Rt . get < Counter >( 'Singleton' ) ;
// Check if the dependencies are obtained
final isObtained = counterAfterDeleted != null ;
final isObtained2 = counterAfterDeleted2 != null ;
final isObtained3 = counterAfterDeleted3 != null ;
final isObtained4 = counterAfterDeleted4 != null ;
// Print if the dependencies are obtained
print ( 'isObtained: $ isObtained ' ) ; // isObtained: true
print ( 'isObtained2: $ isObtained2 ' ) ; // isObtained2: false
print ( 'isObtained3: $ isObtained3 ' ) ; // isObtained3: false
print ( 'isObtained4: $ isObtained4 ' ) ; // isObtained4: false
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . unregister
The Rt . unregister
method is used to unregister the dependency from the Reactter.
It returns true
if the dependency is unregistered successfully, otherwise return false
.
Syntax
bool Rt . unregister < T >([ String ? id]) ;
Parameters
id
: An optional identifier for the T
dependency. If not provided, the method will attempt to unregister the default instance of the dependency.
Example
See the example below to understand how to use the Rt . unregister
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create the dependencies with different dependency modes
Rt . create < Counter >(() => Counter ()) ;
Rt . builder < Counter >(() => Counter () , id : 'Builder' ) ;
Rt . factory < Counter > (() => Counter () , id : 'Factory' ) ;
Rt . singleton < Counter >(() => Counter () , id : 'Singleton' ) ;
// Unregister the dependencies
final isUnregistered = Rt . unregister < Counter >() ;
final isUnregistered2 = Rt . unregister < Counter >( 'Builder' ) ;
final isUnregistered3 = Rt . unregister < Counter >( 'Factory' ) ;
final isUnregistered4 = Rt . unregister < Counter >( 'Singleton' ) ;
// All should return false, because the dependencies has an active instance
print ( 'isUnregistered: $ isUnregistered ' ) ; // isUnregistered: false
print ( 'isUnregistered2: $ isUnregistered2 ' ) ; // isUnregistered2: false
print ( 'isUnregistered3: $ isUnregistered3 ' ) ; // isUnregistered3: false
print ( 'isUnregistered4: $ isUnregistered4 ' ) ; // isCounterUnregistered4: false
// Delete the dependencies
Rt . destroy < Counter >(onlyInstance : true ) ;
Rt . delete < Counter >( 'Builder' ) ;
Rt . delete < Counter >( 'Factory' ) ;
Rt . delete < Counter >( 'Singleton' ) ;
// Unregister the dependencies after deleted
final isUnregisteredAfterDeleted = Rt . unregister < Counter >() ;
final isUnregisteredAfterDeleted2 = Rt . unregister < Counter >( 'Builder' ) ;
final isUnregisteredAfterDeleted3 = Rt . unregister < Counter >( 'Factory' ) ;
final isUnregisteredAfterDeleted4 = Rt . unregister < Counter >( 'Singleton' ) ;
// These should return true, because the instance has been deleted but the dependency is still registered
'isUnregisteredAfterDeleted: $ isUnregisteredAfterDeleted ' ,
) ; // isUnregisteredAfterDeleted: true
'isUnregisteredAfterDeleted3: $ isUnregisteredAfterDeleted3 ' ,
) ; // isUnregisteredAfterDeleted3: true
// These should return false, because the instance and its registration has been deleted
'isUnregisteredAfterDeleted2: $ isUnregisteredAfterDeleted2 ' ,
) ; // isUnregisteredAfterDeleted2: false
'isUnregisteredAfterDeleted4: $ isUnregisteredAfterDeleted4 ' ,
) ; // isUnregisteredAfterDeleted4: false
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class
Rt . isActive
The Rt . isActive
method is used to check if the dependency is registered in Reactter.
It returns true
if the dependency is registered, otherwise return false
.
Syntax
bool Rt . isActive < T >([ String ? id]) ;
Parameters
id
: An optional identifier for the T
dependency. If not provided, the method will attempt to check the default instance of the dependency.
Example
See the example below to understand how to use the Rt . isActive
method in different scenarios.
import 'package:flutter/material.dart' ;
import 'package:reactter/reactter.dart' ;
// Create the dependencies with different dependency modes
final counter = Counter () ;
final counter2 = Rt . builder < Counter >(() => Counter () , id : 'Builder' ) ;
final counter3 = Rt . factory < Counter > (() => Counter () , id : 'Factory' ) ;
final counter4 = Rt . singleton < Counter >(
// Check if the instances are registered
final isActive = Rt . isActive (counter) ;
final isActive2 = Rt . isActive (counter2) ;
final isActive3 = Rt . isActive (counter3) ;
final isActive4 = Rt . isActive (counter4) ;
// Print if the instances are registered
print ( 'isActive: $ isActive ' ) ; // isActive: false
print ( 'isActive2: $ isActive2 ' ) ; // isActive2: true
print ( 'isActive3: $ isActive3 ' ) ; // isActive3: true
print ( 'isActive4: $ isActive4 ' ) ; // isActive4: true
// Delete the dependencies
Rt . destroy < Counter >(onlyInstance : true ) ;
Rt . delete < Counter >( 'Builder' ) ;
Rt . delete < Counter >( 'Factory' ) ;
Rt . delete < Counter >( 'Singleton' ) ;
// Check if the instances are registered
final isActiveAfterDeleted = Rt . isActive (counter) ;
final isActiveAfterDeleted2 = Rt . isActive (counter2) ;
final isActiveAfterDeleted3 = Rt . isActive (counter3) ;
final isActiveAfterDeleted4 = Rt . isActive (counter4) ;
// Print if the instances are registere after deleted
'isActiveAfterDeleted: $ isActiveAfterDeleted ' ,
) ; // isActiveAfterDeleted: false
'isActiveAfterDeleted2: $ isActiveAfterDeleted2 ' ,
) ; // isActiveAfterDeleted2: false
'isActiveAfterDeleted3: $ isActiveAfterDeleted3 ' ,
) ; // isActiveAfterDeleted3: false
'isActiveAfterDeleted4: $ isActiveAfterDeleted4 ' ,
) ; // isActiveAfterDeleted4: true
class MyApp extends StatelessWidget {
Widget build ( BuildContext context) {
child : Text ( 'See the output in the terminal' ) ,
import 'package:reactter/reactter.dart' ;
// Create a reactive state using the ` Signal ` class