buildStackChild static method
Widget
buildStackChild(
- BaseNode node,
- BaseNode parent,
- BuildContext context, {
- WidgetNodeTransformerManager? manager,
- Widget? childWidget,
- required BaseNode? widestChild,
- required BaseNode? tallestChild,
- required AlignmentModel commonAlignment,
- required WidgetBuildSettings settings,
Implementation
static Widget buildStackChild(
BaseNode node,
BaseNode parent,
BuildContext context, {
WidgetNodeTransformerManager? manager,
Widget? childWidget,
required BaseNode? widestChild,
required BaseNode? tallestChild,
required AlignmentModel commonAlignment,
required WidgetBuildSettings settings,
}) {
assert(childWidget != null || manager != null,
'Either childWidget or manager must be provided.');
Widget child = childWidget ??
manager!.buildWidgetFromNode(node, context, settings: settings);
final bool potentiallyPositionable =
node.alignment == AlignmentModel.none ||
(parent.isOneOrBothWrap && node.alignment != commonAlignment);
if (potentiallyPositionable) {
// You cannot use the Align widget when inside a shrink-wrapping Stack.
// The Align RenderBox will force the Stack to grow as much as possible.
// Positioned widgets are only laid out after the Stack lays out its
// concrete children and figures out its own size. So for wrapping stacks,
// we need to use Positioned instead of Align.
//
// The behavior is absolutely different, but it's the best compromise we
// can do.
if (node.alignment != AlignmentModel.none &&
parent.childrenOrEmpty.length > 1) {
final align = node.alignment.data!;
child = Positioned(
left: align.x <= 0
? node.outerBoxLocal.left - parent.innerBoxLocal.edgeLeft
: null,
right: align.x >= 0
? (parent.innerBoxLocal.width - node.outerBoxLocal.right) +
parent.innerBoxLocal.edgeRight
: null,
top: align.y <= 0
? node.outerBoxLocal.top - parent.innerBoxLocal.edgeTop
: null,
bottom: align.y >= 0
? (parent.innerBoxLocal.height - node.outerBoxLocal.bottom) +
parent.innerBoxLocal.edgeBottom
: null,
child: child,
);
} else {
child = wrapWithPositioned(
node,
parent,
child,
isWidest: widestChild?.id == node.id,
isTallest: tallestChild?.id == node.id,
);
}
} else {
if (node.alignment != commonAlignment) {
child = Align(
alignment: node.alignment.flutterAlignment!,
child: child,
);
}
}
return KeyedSubtree(
key: ValueKey(
'Static Stack child [${node.id}](${node.name})<${node.type}> on parent [${parent.id}](${parent.name})<${parent.type}>',
),
child: child,
);
}