defaultChildFactory<T extends InflatedChildHandle> static method
T
defaultChildFactory<T extends InflatedChildHandle>({
- required Object id,
- required InflatingRenderObjectMixin<
RenderObject, InflatingParentData< parent,RenderObject> , InflatedChildHandle> - RenderObject? render,
- Element? context,
- Widget? widget,
The default child handle factory for BaseBoxyChild subclasses, constructs an appropriate child based on the the generic type argument.
Implementation
static T defaultChildFactory<T extends InflatedChildHandle>({
required Object id,
required InflatingRenderObjectMixin parent,
RenderObject? render,
Element? context,
Widget? widget,
}) {
R? expectType<R extends RenderObject>() {
assert(() {
if (render != null && render is! R) {
throw FlutterError(
'A ${parent.context.widget} widget was given a child of the wrong type: $render\n'
'Expected child of type $R\n',
);
}
return true;
}());
return render as R?;
}
final BaseBoxyChild handle;
if (render is RenderBox || T == BoxyChild) {
handle = BoxyChild(
id: id,
parent: parent,
widget: widget,
render: expectType(),
context: context,
);
} else if (render is RenderSliver || T == SliverBoxyChild) {
handle = SliverBoxyChild(
id: id,
parent: parent,
widget: widget,
render: expectType(),
context: context,
);
} else if (T == BaseBoxyChild) {
handle = BaseBoxyChild(
id: id,
parent: parent,
widget: widget,
render: render,
context: context,
);
} else {
throw FlutterError(
'A ${parent.context.widget} widget was given a child with an unknown type: $render\n'
'No child factory is available for $T\n');
}
return handle as T;
}