inflate<T extends ChildHandleType> method

T inflate<T extends ChildHandleType>(
  1. Widget widget,
  2. {Object? id}
)

Dynamically inflates a widget as a child of this boxy, should only be called in BoxyChild.layout.

If id is not provided the resulting child has an id of indexedChildCount which gets incremented.

After calling this method the child becomes available with getChild, it is removed before the next call to BoxyChild.layout.

A child's state will only be preserved if inflated with the same id as the previous layout.

Unlike children passed to the widget, Keys cannot be used to move state from one child id to another. You may hit duplicate GlobalKey assertions from children inflated during the previous layout.

Implementation

T inflate<T extends ChildHandleType>(Widget widget, {Object? id}) {
  final render = this.render;
  assert(() {
    if (debugPhase == BoxyDelegatePhase.dryLayout) {
      render.debugThrowLayout(
          CannotInflateError(delegate: this, render: render));
    } else if (debugPhase != BoxyDelegatePhase.layout) {
      throw FlutterError(
          'The $this boxy attempted to inflate a widget outside of the layout method.\n'
          'You should only call `inflate` from its overridden methods.');
    }
    return true;
  }());
  return render.inflate<T>(widget, id: id);
}