createViewContainer method

ReadClassMemberExpr createViewContainer(
  1. NodeReference nodeReference,
  2. int nodeIndex,
  3. bool isPrivate, [
  4. int? parentNodeIndex,
])

Implementation

o.ReadClassMemberExpr createViewContainer(
  NodeReference nodeReference,
  int nodeIndex,
  bool isPrivate, [
  int? parentNodeIndex,
]) {
  var renderNode = nodeReference.toReadExpr();
  var fieldName = '_appEl_$nodeIndex';
  // Create instance field for app element.
  storage.allocate(
    fieldName,
    outputType: o.importType(Identifiers.ViewContainer),
    modifiers: const [
      o.StmtModifier.Private,
      o.StmtModifier.Final,
      o.StmtModifier.Late,
    ],
  );

  // Write code to create an instance of ViewContainer.
  // Example:
  //     this._appEl_2 = new import7.ViewContainer(2,0,this,this._anchor_2);
  var statement = o.WriteClassMemberExpr(
      fieldName,
      o.importExpr(Identifiers.ViewContainer).instantiate([
        o.literal(nodeIndex),
        o.literal(parentNodeIndex),
        o.THIS_EXPR,
        renderNode
      ])).toStmt();
  _createMethod.addStmt(statement);
  var appViewContainer = o.ReadClassMemberExpr(fieldName);
  if (!isPrivate) {
    viewContainers.add(appViewContainer);
  }
  return appViewContainer;
}