NodeProvider<N extends NodeInterface>.reuse constructor
NodeProvider<N extends NodeInterface>.reuse ({
- Key? key,
- required N create(),
- required Widget builder(
- BuildContext context,
- N node
If the node you want to use might be created in a parent scope but you don't want to recreate it,use this constructor.
If node does not exist, it will be created.
❌ Don't do this:
final yourNode = YourNode();
NodeProvider.reuse(
create: () => yourNode,
builder: (context, node) => MyWidget(node: yourNode),
);
The node returned by the builder might not be the one you created.
✅ Do this:
NodeProvider.reuse(
create: () => YourNode(),
builder: (context, node) => MyWidget(node: node),
);
Implementation
NodeProvider.reuse({
super.key,
required N Function() create,
required this.builder,
}) : child = null,
nodes = [create],
reuse = true;