wrapChildren method
Wraps navigation bar items with control data for selection tracking.
Takes a list of NavigationBarItem children and wraps each with NavigationChildControlData that tracks the item's index and selection state. Only selectable items receive a selection index, while non-selectable items have a null selection index.
Parameters:
context(BuildContext, required): Build context for inherited data.children(List<NavigationBarItem>, required): Navigation items to wrap.
Returns: List<Widget> — wrapped navigation items with control data.
Example:
final wrappedItems = wrapChildren(
context,
[
NavigationBarItem(icon: Icon(Icons.home), selectable: true),
NavigationBarItem(icon: Icon(Icons.settings), selectable: true),
],
);
Implementation
List<Widget> wrapChildren(
BuildContext context,
List<NavigationBarItem> children,
) {
int index = 0;
List<Widget> newChildren = List.of(children);
for (var i = 0; i < children.length; i++) {
if (children[i].selectable) {
newChildren[i] = Data.inherit(
data: NavigationChildControlData(index: index, actualIndex: i),
child: children[i],
);
index++;
} else {
newChildren[i] = Data.inherit(
data: NavigationChildControlData(index: null, actualIndex: i),
child: children[i],
);
}
}
return newChildren;
}