buildSingleWidget method
DataScopeWidget
buildSingleWidget(
- ScopeManager parentScope,
- ItemTemplate itemTemplate, {
- required int itemIndex,
- required dynamic itemData,
- Key? key,
inherited
Implementation
DataScopeWidget buildSingleWidget(
ScopeManager parentScope, ItemTemplate itemTemplate,
{required int itemIndex, required dynamic itemData, Key? key}) {
// create a new scope for each item template
ScopeManager templatedScope = parentScope.createChildScope();
// add the item's index and data to the templated scope
templatedScope.dataContext.addDataContextById(itemTemplate.name, itemData);
templatedScope.dataContext.addDataContextById(itemTemplate.indexId, itemIndex);
WidgetModel model =
templatedScope.buildWidgetModelFromDefinition(itemTemplate.template);
Widget templatedWidget = templatedScope.buildWidgetFromModel(model);
// Widget templatedWidget =
// templatedScope.buildWidgetFromDefinition(itemTemplate.template);
// wraps the templated widget inside a DataScopeWidget so we can constrain the data scope
return DataScopeWidget(
scopeManager: templatedScope,
child: templatedWidget,
key: key,
);
}