align_positioned 1.0.7
align_positioned: ^1.0.7 copied to clipboard
A widget that aligns, positions and optionally sizes its child within itself.
align_positioned #
A widget that aligns, positions and optionally sizes its child within itself.
Align and Position #
The alignment parameter works as expected. For example,
Alignment.bottomRight represents the bottom right of the container,
and Alignment(0.0, 0.0) represents the center of the container.
The distance from -1.0 to +1.0 is the distance from one side of the rectangle
to the other side of the rectangle.
If touch is Touch.inside, then alignment works just like the alignment
for the Align widget, aligning the child inside of the container.
However, if touch is Touch.outside, then the alignment happens outside of
the container.
As another example, if touch is Touch.inside, then Alignment(1.0, 0.0) makes the child's
right side touch the right side of the container (it touches the container from the inside).
But if touch is Touch.outside, then Alignment(1.0, 0.0) makes the child's
left side touch the right side of the container (it touches the container from the outside).
Parameters dx and dy can be positive or negative, and move the child horizontally and
vertically, in pixels.
Parameters moveByChildWidth and moveByChildHeight can be positive or negative, and move the child
horizontally and vertically, but the unit here is not pixels, but child widths and heights.
Parameters moveByContainerWidth and moveByContainerHeight can be positive or negative, and move the child
horizontally and vertically, but the unit here is not pixels, but container widths and heights.
Align and Position Examples #
The below image shows the center of the child positioned 15 pixels to the right of the top-left corner of the container:
[alt text]
AlignPositioned(
child: child,
alignment: Alignment.topLeft,
touch: Touch.inside,
dx: 15.0, // Move 4 pixels to the right.
moveByChildWidth: -0.5, // Move half child width to the left.
moveByChildHeight: -0.5); // Move half child height to the top.
Then, to move the child one container width to the right, and one container height to the bottom:
[alt text]
AlignPositioned(
child: child,
alignment: Alignment.topLeft,
touch: Touch.inside,
dx: 15.0, // Move 4 pixels to the right.
moveByChildWidth: -0.5, // Move half child width to the left.
moveByChildHeight: -0.5, // Move half child height to the top.
moveByContainerWidth: 1.0, // Move one container width to the right.
moveByContainerHeight: 1.0); // Move one container height to the bottom.
Please, check the example tab for the effects seen below:
[alt text]
Sizing #
Optionally, you can also define the child size:
-
childWidthis the child width, in pixels. -
childHeightis the child height, in pixels. -
minChildWidthis the minimum width, in pixels. It has precedence overchildWidth. -
minChildHeightis the minimum height, in pixels. It has precedence overchildHeight. -
maxChildWidthis the maximum width, in pixels. It has precedence overchildWidth. -
maxChildHeightis the maximum height, in pixels. It has precedence overchildHeight. -
childWidthRatiois the child width, as a fraction of the container width. If between 0.0 and 1.0, the child will be smaller than its container. If more than 1.0, the child will be larger than its container. You cannot define bothchildWidthRatioandchildWidthat the same time. -
childHeightRatiois the child height, as a fraction of the container height. If between 0.0 and 1.0, the child will be smaller than its container. If more than 1.0, the child will be larger than its container. You cannot define bothchildHeightRatioandchildHeightat the same time. -
minChildWidthRatiois the minimum child width, as a fraction of the container width. It has precedence overchildWidth. If bothminChildWidthandminChildWidthRatioare defined, both will be applied (the minimum will be the larger one). -
minChildHeightRatio. is the minimum child height, as a fraction of the container height. It has precedence overchildHeight. If bothminChildHeightandminChildHeightRatioare defined, both will be applied (the minimum will be the larger one). -
maxChildWidthRatiois the maximum child width, as a fraction of the container width. It has precedence overchildWidth. If bothmaxChildWidthandmaxChildWidthRatioare defined, both will be applied (the maximum will be the smaller one). -
maxChildHeightRatiois the maximum child height, as a fraction of the container height. It has precedence overchildHeight. If bothmaxChildHeightandmaxChildHeightRatioare defined, both will be applied (the maximum will be the smaller one). -
winsdecides what happens if the minimum size is larger then the maximum size. IfwinsisWins.min, the default, the minimum size will be used.
IfwinsisWins.max, the maximum size will be used.
Usage #
Import the package #
First, add align_positioned as a dependency in your pubspec.yaml
Then, import it:
import 'package:align_positioned/align_positioned.dart';