Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbsolutePositioned children won't expand the layout #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions lib/figma_auto_layout.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library figma_auto_layout;

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:signed_spacing_flex/signed_spacing_flex.dart';

export 'package:signed_spacing_flex/signed_spacing_flex.dart'
Expand Down Expand Up @@ -275,13 +276,11 @@ class FigmaAutoLayout extends FigmaAutoLayoutChild {
return newChildren;
}

/// Generates a list of absolute positioned children at their appropriate positions
/// to be displayed on top of the normal children.
List<Widget> _buildPositionedChildrenUnderneath(BuildContext context) {
List<Widget> _buildPositionedChildren(BuildContext context, bool showOnTop) {
var newChildren = <Widget>[];

for (final child in children) {
if (child.hasAbsolutePosition && !child.showOnTop) {
if (child.hasAbsolutePosition && child.showOnTop == showOnTop) {
newChildren.add(
Positioned.directional(
textDirection: _getTextDirection(context),
Expand All @@ -294,29 +293,20 @@ class FigmaAutoLayout extends FigmaAutoLayoutChild {
);
}
}
return newChildren;
if (newChildren.isEmpty) return [];
return [Positioned.fill(child: Stack(children: newChildren))];
}

/// Generates a list of absolute positioned children at their appropriate positions
/// to be displayed on top of the normal children.
List<Widget> _buildPositionedChildrenUnderneath(BuildContext context) {
return _buildPositionedChildren(context, false);
}

/// Generates a list of absolute positioned children at their appropriate positions.
/// to be displayed underneath the normal children.
List<Widget> _buildPositionedChildrenOnTop(BuildContext context) {
var newChildren = <Widget>[];

for (final child in children) {
if (child.hasAbsolutePosition && child.showOnTop) {
newChildren.add(
Positioned.directional(
textDirection: _getTextDirection(context),
start: child.start,
top: child.top,
end: child.end,
bottom: child.bottom,
child: child,
),
);
}
}
return newChildren;
return _buildPositionedChildren(context, true);
}

@override
Expand Down Expand Up @@ -344,7 +334,7 @@ class FigmaAutoLayout extends FigmaAutoLayoutChild {
),
),
),
..._buildPositionedChildrenOnTop(context),
..._buildPositionedChildrenOnTop(context)
],
);
}
Expand Down