BuildContext.use
Esta página aún no está disponible en tu idioma.
BuildContext.use
is a method that gets an instance of T
dependency from the nearest ancestor provider( RtProvider
or RtComponent
) of type T
.
Syntax & description
context
: TheBuildContext
object, which provides information about the current widget in the tree.-
T
: The type of the dependency you want to access. These are some points to consider:- If the type is nullable, the method will return
null
if the dependency is not found. - If the type is not nullable, the method will throw an exception if the dependency is not found.
- If the type is nullable, the method will return
id
: An optional identifier for theT
dependency. If omitted, the dependency will be located by its type(T
).
Usage
This following example demonstrates how to use BuildContext.use
:
In this example, the Counter
widget uses BuildContext.use
to get the instance of CounterController
from the nearest ancestor provider(located in main.dart
).