createProviderNode method
Creates a ProviderNode for this element.
Note that childNodeCount
can be greater than children.length
, as it
counts nodes that can't produce providers such as HTML text and comments.
Implementation
ProviderNode createProviderNode(
int childNodeCount, List<ProviderNode> children) {
final providers = <ProviderInstance>[];
final nodeIndex = this.nodeIndex!;
if (childNodeCount == 0) {
// If there aren't any child nodes, both regular and view providers are
// injectable within the same range ([nodeIndex, nodeIndex]), so they can
// both be added to the same `ProviderNode`.
_createProviderInstances(providers, providers);
} else {
// Otherwise view providers must be added to their own `ProviderNode`.
// This node is added as a child because its restricted range ([nodeIndex,
// nodeIndex]) lies within the range for normal providers ([nodeIndex,
// nodeIndex + childNodeCount]).
final viewProviders = <ProviderInstance>[];
_createProviderInstances(providers, viewProviders);
if (viewProviders.isNotEmpty) {
children.add(ProviderNode(
nodeIndex,
nodeIndex,
providers: viewProviders,
));
}
}
return ProviderNode(
nodeIndex,
nodeIndex + childNodeCount,
providers: providers,
children: children,
);
}