mount method
- @override
override
Add this element to the tree in the given slot of the given parent.
The framework calls this function when a newly created element is added to the tree for the first time. Use this method to initialize state that depends on having a parent. State that is independent of the parent can more easily be initialized in the constructor.
This method transitions the element from the "initial" lifecycle state to the "active" lifecycle state.
Implementation
@override
void mount(Element parent, dynamic newSlot) {
assert(() {
final List<Widget> badAncestors = <Widget>[];
Element ancestor = parent;
while (ancestor != null) {
if (ancestor is ParentDataElement<RenderObjectWidget>) {
badAncestors.add(ancestor.widget);
} else if (ancestor is RenderObjectElement) {
if (widget.debugIsValidAncestor(ancestor.widget))
break;
badAncestors.add(ancestor.widget);
}
ancestor = ancestor._parent;
}
if (ancestor != null && badAncestors.isEmpty)
return true;
throw FlutterError(
'Incorrect use of ParentDataWidget.\n' +
widget.debugDescribeInvalidAncestorChain(
description: '$this',
ownershipChain: parent.debugGetCreatorChain(10),
foundValidAncestor: ancestor != null,
badAncestors: badAncestors
)
);
}());
super.mount(parent, newSlot);
}