RepositoryProvider<T> constructor
Takes a Create
function that is responsible for creating the repository
and a child
which will have access to the repository via
RepositoryProvider.of(context)
.
It is used as a dependency injection (DI) widget so that a single instance
of a repository can be provided to multiple widgets within a subtree.
RepositoryProvider(
create: (context) => RepositoryA(),
child: ChildA(),
);
Lazily creates the repository unless lazy
is set to false
.
RepositoryProvider(
lazy: false,`
create: (context) => RepositoryA(),
child: ChildA(),
);
Implementation
RepositoryProvider({
required Create<T> create,
Key? key,
Widget? child,
bool? lazy,
}) : super(
key: key,
create: create,
dispose: (_, __) {},
child: child,
lazy: lazy,
);