align_positioned 1.1.4

align_positioned #

Why is this widget an indispensable tool?

When your desired layout feels too complex for Columns and Rows, AlignPositioned widget is a real life saver. Flutter is very composable, which is good, but sometimes it's unnecessarily complex to translate some layout requirement into a composition of simpler widgets.

The AlignPositioned aligns, positions, sizes, rotates and transforms its child in relation to both the container and the child itself. In other words, it lets you easily and declaratively define where and how a widget should appear in relation to another.

For example, you can tell it to position the top-left of its child at 15 pixels to the left of the top-left corner of the container, plus move it two thirds of the child's height to the bottom plus 10 pixels, and then rotate 15 degrees. Do you even know how to start doing this by composing basic Flutter widgets? Maybe, but with AlignPositioned it's much easier, and it takes a single widget.

The AlignPositioned widget is specially helpful for animations, since you can just calculate the final position and size you want for each frame. Without it you may find yourself having to animate a composition of widgets.

How it works #

Add align_positioned as a dependency in your pubspec.yaml file, then import it:

import 'package:align_positioned/align_positioned.dart';

Pass the AlignPositioned a child, and then one or more of the following parameters:

AlignPositioned(
   child: child,           
   alignment: ...,
   dx: ...,
   dy: ...,
   moveByChildWidth: ...,
   moveByChildHeight: ...,
   moveByContainerWidth: ...,
   moveByContainerHeight: ...,
   childWidth: ...,
   childHeight: ...,
   minChildWidth: ...,
   minChildHeight: ...,
   maxChildWidth: ...,
   maxChildHeight: ...,
   childWidthRatio: ...,
   childHeightRatio: ...,
   minChildWidthRatio: ...,
   minChildHeightRatio: ...,
   maxChildWidthRatio: ...,
   maxChildHeightRatio: ...,
   rotateDegrees: ...,
   matrix4Transform: ...,
   wins: ...,
   touch: ...,       
   ); 

Let's study each parameter in detail:

Align and Position parameters #

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

Size Parameters #

Optionally, you can also define the child size:

  • childWidth is the child width, in pixels.

  • childHeight is the child height, in pixels.

  • minChildWidth is the minimum width, in pixels. It has precedence over childWidth.

  • minChildHeight is the minimum height, in pixels. It has precedence over childHeight.

  • maxChildWidth is the maximum width, in pixels. It has precedence over childWidth.

  • maxChildHeight is the maximum height, in pixels. It has precedence over childHeight.

  • childWidthRatio is 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. If you define both childWidthRatio and childWidth they will be added.

  • childHeightRatio is 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. If you define both childHeightRatio and childHeight they will be added.

  • minChildWidthRatio is the minimum child width, as a fraction of the container width. It has precedence over childWidth. If both minChildWidth and minChildWidthRatio are 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 over childHeight. If both minChildHeight and minChildHeightRatio are defined, both will be applied (the minimum will be the larger one).

  • maxChildWidthRatio is the maximum child width, as a fraction of the container width. It has precedence over childWidth. If both maxChildWidth and maxChildWidthRatio are defined, both will be applied (the maximum will be the smaller one).

  • maxChildHeightRatio is the maximum child height, as a fraction of the container height. It has precedence over childHeight. If both maxChildHeight and maxChildHeightRatio are defined, both will be applied (the maximum will be the smaller one).

  • wins decides what happens if the minimum size is larger then the maximum size. If wins is Wins.min, the default, the minimum size will be used.
    If wins is Wins.max, the maximum size will be used.

Rotate and Transform #

Optionally, you can also define rotation and transformation:

  • rotateDegrees is the rotation, in degrees (1 turn is 360 degrees). The position of the axis of the rotation (the "origin") depends on the alignment parameter and the parent. So, for example, Alignment.center means the axis of rotation is at the center of the parent.

  • matrix4Transform lets you apply any transformation to the child. This uses Matrix4Transform instead of Matrix4, since it's easier to use. However, you can still use Matrix4 directly with the constructor Matrix4Transform.from(matrix4).

alt text

Using AlignPositioned inside of a Stack #

A Stack positions its children relative to the edges of its box. The Stack documentation contains this text:

In particular, when using a Stack you can't position children relative to their size or the stack's own size.

However, by using AlignPositioned you can do precisely that: position (and size, rotate and transform) children relative to their size or the Stack's own size, and consequently in relation to the other widgets inside of the Stack.

If you recall how a Stack works, each of its child widgets is either positioned or non-positioned. The stack sizes itself to contain all the non-positioned children, which are positioned according to the stacks's alignment parameter. Next, the positioned children are laid out.

If you use the AlignPositioned default constructor and put it inside of a Stack it will be a non-positioned child.

To create a positioned widget, use the AlignPositioned.expand() constructor. The AlignPositioned will then expand and fix itself to the corners of the Stack. In other words, the Stack will size itself to their other non-positioned widgets, and then you can use the AlignPositioned to layout its child in relation to the Stack.

Example:

Stack(
  children: [      
    Container(...),
    Positioner(child: Container(...)),                                        
    AlignPositioned(...),
    AlignPositioned.expand(...),
    ...
    ]);

The Flutter packages I've authored:

---
https://github.com/marcglasberg
https://twitter.com/glasbergmarcelo
https://stackoverflow.com/users/3411681/marcg
https://medium.com/@marcglasberg

[1.0.4] - 2019/02/22

  • Code and examples.

[1.0.6] - 2019/02/23

  • Added moveByContainerWidth and moveByContainerHeight.

[1.0.7] - 2019/02/23

  • Added size parameters.

[1.0.8] - 2019/08/07

  • Better docs.

[1.1.0] - 2019/08/17

  • AlignPositioned inside of a Stack.

[1.1.4] - 2019/08/23

  • ChildHeightRatio and childHeight may be present at the same time.
  • Rotate.
  • Transform.

example/main.dart

import 'package:align_positioned/align_positioned.dart';
import 'package:flutter/material.dart';
import 'package:matrix4_transform/matrix4_transform.dart';

void main() async => runApp(MaterialApp(home: Demo()));

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //

    return Scaffold(
      appBar: AppBar(title: const Text('Align Positioned Widget Example')),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              SizedBox(height: 50, width: double.infinity),
              //
              Container(
                  width: 150,
                  height: 150,
                  color: Colors.yellow,
                  child: Stack(children: circlesInside())),
              //
              SizedBox(height: 50, width: double.infinity),
              //
              Container(
                  width: 150,
                  height: 150,
                  color: Colors.yellow,
                  child: Stack(children: circlesOutside())),
              //
              SizedBox(height: 60),
              //
              Container(
                  width: 150,
                  height: 150,
                  color: Colors.yellow,
                  child: Stack(children: circlesWithOffset())),
              SizedBox(height: 100),
              //
              Container(
                  width: 150,
                  height: 150,
                  color: Colors.yellow,
                  child: Stack(children: circlesWithNamedAlignments())),
              //
              SizedBox(height: 50),
              //
              Container(
                  width: 150,
                  height: 150,
                  color: Colors.yellow,
                  child: Stack(children: circlesWithDWidthAndDHeightInside())),
              //
              SizedBox(height: 50),
              //
              Container(
                  width: 150,
                  height: 150,
                  color: Colors.yellow,
                  child: Stack(children: circlesWithDWidthAndDHeightOutside())),
              //
              SizedBox(height: 80),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.blue,
                child: Stack(
                  children: <Widget>[
                    AlignPositioned(
                      touch: Touch.inside,
                      alignment: Alignment.topLeft,
                      dx: 15.0,
                      moveByChildWidth: -0.5,
                      moveByChildHeight: -0.5,
                      child: circle(Color(0x50000000), 60.0),
                    ),
                    AlignPositioned(
                      touch: Touch.inside,
                      alignment: Alignment.topLeft,
                      dx: 15.0,
                      moveByChildWidth: -0.5,
                      moveByChildHeight: -0.5,
                      child: circle(Colors.white, 5.0),
                    ),
                    AlignPositioned(
                      rotateDegrees: 180,
                      touch: Touch.inside,
                      alignment: Alignment.topLeft,
                      dx: 15.0,
                      moveByChildWidth: -0.5,
                      moveByChildHeight: -0.5,
                      child: circle(Color(0x50000000), 60.0),
                    ),
                    AlignPositioned(
                      rotateDegrees: 180,
                      touch: Touch.inside,
                      alignment: Alignment.topLeft,
                      dx: 15.0,
                      moveByChildWidth: -0.5,
                      moveByChildHeight: -0.5,
                      child: circle(Colors.white, 5.0),
                    ),
                  ],
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.red,
                child: Stack(
                  children: <Widget>[
                    AlignPositioned(
                      touch: Touch.inside,
                      alignment: Alignment.topLeft,
                      dx: 15.0,
                      moveByChildWidth: -0.5,
                      moveByChildHeight: -0.5,
                      moveByContainerWidth: 1,
                      moveByContainerHeight: 1,
                      child: circle(Color(0x50000000), 60.0),
                    ),
                    AlignPositioned(
                      touch: Touch.inside,
                      alignment: Alignment.topLeft,
                      dx: 15.0,
                      moveByChildWidth: -0.5,
                      moveByChildHeight: -0.5,
                      moveByContainerWidth: 1,
                      moveByContainerHeight: 1,
                      child: circle(Colors.white, 5.0),
                    ),
                  ],
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.green,
                child: Stack(
                  children: <Widget>[
                    for (double i = 0; i < 360 * 2; i += 5)
                      AlignPositioned(
                        alignment: Alignment.center,
                        rotateDegrees: i,
                        touch: Touch.inside,
                        moveByContainerWidth: 0.5 / 2 / 360 * i,
                        childWidthRatio: 0.5 / 2 / 360 * i,
                        childHeightRatio: 0.5 / 2 / 360 * i,
                        child: circle(Colors.white, 15.0),
                      )
                  ],
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.green,
                child: Stack(
                  children: <Widget>[
                    for (double i = 0; i < 360; i += 45)
                      AlignPositioned(
                        alignment: Alignment.center,
                        rotateDegrees: i,
                        child: Container(color: Colors.black, width: 60, height: 6),
                      ),
                    for (double i = 0; i < 360; i += 45)
                      AlignPositioned(
                        alignment: Alignment.center,
                        dx: 50,
                        dy: 60,
                        rotateDegrees: i,
                        child: Container(color: Colors.black, width: 40, height: 8),
                      ),
                    for (double i = 0; i < 360; i += 5)
                      AlignPositioned(
                        alignment: Alignment.bottomLeft,
                        rotateDegrees: i,
                        child: Container(
                            color: Colors.black.withOpacity(i / 360 * .8), width: 100, height: 10),
                      )
                  ],
                ),
              ),
              //
              SizedBox(height: 120),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.purple,
                child: Stack(
                  children: <Widget>[
                    AlignPositioned(
                      alignment: Alignment.center,
                      rotateDegrees: 45,
                      child: Container(color: Colors.yellow, width: 60, height: 20),
                    ),
                    AlignPositioned(
                      alignment: Alignment.center,
                      matrix4Transform: Matrix4Transform().scale(2),
                      child: Container(color: Colors.green.withOpacity(0.5), width: 60, height: 20),
                    ),
                    AlignPositioned(
                      alignment: Alignment.center,
                      rotateDegrees: 45,
                      matrix4Transform: Matrix4Transform().scale(2),
                      child: Container(color: Colors.red.withOpacity(0.5), width: 60, height: 20),
                    ),
                    AlignPositioned(
                      alignment: Alignment.center,
                      rotateDegrees: 45,
                      matrix4Transform: Matrix4Transform().scale(2).rotateDegrees(90),
                      child: Container(color: Colors.blue.withOpacity(0.5), width: 60, height: 20),
                    ),
                  ],
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.red,
                child: AlignPositioned(
                  alignment: Alignment.center,
                  childHeightRatio: 0.5,
                  moveByContainerHeight: 0.25,
                  childWidth: 75,
                  wins: Wins.min,
                  child: Container(color: Color(0x50000000)),
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.red,
                child: AlignPositioned(
                  alignment: Alignment.center,
                  childHeightRatio: 0.5,
                  moveByChildHeight: 0.5,
                  childWidth: 75,
                  wins: Wins.min,
                  child: Container(color: Color(0x50000000)),
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.red,
                child: AlignPositioned(
                  alignment: Alignment.center,
                  childHeightRatio: 1.0,
                  minChildWidthRatio: 0.66,
                  maxChildWidthRatio: 0.33,
                  wins: Wins.min,
                  child: Container(color: Color(0x50000000)),
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.red,
                child: AlignPositioned(
                  alignment: Alignment.center,
                  childHeightRatio: 1.0,
                  minChildWidthRatio: 0.66,
                  maxChildWidthRatio: 0.33,
                  wins: Wins.max,
                  child: Container(color: Color(0x50000000)),
                ),
              ),
              //
              SizedBox(height: 50),
              //
              Container(
                width: 150,
                height: 150,
                color: Colors.red,
                child: AlignPositioned(
                  alignment: Alignment.center,
                  childHeightRatio: 1.20,
                  moveByContainerHeight: 0.10,
                  childWidth: 190,
                  wins: Wins.max,
                  child: Container(color: Color(0x50000000)),
                ),
              ),
              //
              SizedBox(height: 50),
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> circlesWithDWidthAndDHeightInside() {
    var children1 = <Widget>[];
    children1.addAll(
        circles(Colors.red, Touch.inside, 0, -1, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.inside, 0, -1, moveByChildWidth: 1.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.green, Touch.inside, 0, -1, moveByChildWidth: -1.0, moveByChildHeight: 0.0));

    children1.addAll(
        circles(Colors.red, Touch.inside, 1, 0, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.inside, 1, 0, moveByChildWidth: 0.0, moveByChildHeight: 1.0));
    children1.addAll(
        circles(Colors.green, Touch.inside, 1, 0, moveByChildWidth: 0.0, moveByChildHeight: -1.0));

    children1.addAll(
        circles(Colors.red, Touch.inside, 0, 1, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.inside, 0, 1, moveByChildWidth: 1.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.green, Touch.inside, 0, 1, moveByChildWidth: -1.0, moveByChildHeight: 0.0));

    children1.addAll(
        circles(Colors.red, Touch.inside, -1, 0, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.inside, -1, 0, moveByChildWidth: 0.0, moveByChildHeight: 1.0));
    children1.addAll(
        circles(Colors.green, Touch.inside, -1, 0, moveByChildWidth: 0.0, moveByChildHeight: -1.0));
    return children1;
  }

  List<Widget> circlesWithDWidthAndDHeightOutside() {
    var children1 = <Widget>[];
    children1.addAll(
        circles(Colors.red, Touch.outside, 0, -1, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.outside, 0, -1, moveByChildWidth: 1.0, moveByChildHeight: 0.0));
    children1.addAll(circles(Colors.green, Touch.outside, 0, -1,
        moveByChildWidth: -1.0, moveByChildHeight: 0.0));

    children1.addAll(
        circles(Colors.red, Touch.outside, 1, 0, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.outside, 1, 0, moveByChildWidth: 0.0, moveByChildHeight: 1.0));
    children1.addAll(
        circles(Colors.green, Touch.outside, 1, 0, moveByChildWidth: 0.0, moveByChildHeight: -1.0));

    children1.addAll(
        circles(Colors.red, Touch.outside, 0, 1, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.outside, 0, 1, moveByChildWidth: 1.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.green, Touch.outside, 0, 1, moveByChildWidth: -1.0, moveByChildHeight: 0.0));

    children1.addAll(
        circles(Colors.red, Touch.outside, -1, 0, moveByChildWidth: 0.0, moveByChildHeight: 0.0));
    children1.addAll(
        circles(Colors.blue, Touch.outside, -1, 0, moveByChildWidth: 0.0, moveByChildHeight: 1.0));
    children1.addAll(circles(Colors.green, Touch.outside, -1, 0,
        moveByChildWidth: 0.0, moveByChildHeight: -1.0));
    return children1;
  }

  List<Widget> circlesInside() {
    var children1 = <Widget>[];
    children1.addAll(circles(Colors.red, Touch.inside, 0, -1));
    children1.addAll(circles(Colors.red, Touch.inside, -1, 0));
    children1.addAll(circles(Colors.red, Touch.inside, 0, 1));
    children1.addAll(circles(Colors.red, Touch.inside, 1, 0));
    children1.addAll(circles(Colors.blue, Touch.inside, -1, -1));
    children1.addAll(circles(Colors.blue, Touch.inside, -1, 1));
    children1.addAll(circles(Colors.blue, Touch.inside, 1, 1));
    children1.addAll(circles(Colors.blue, Touch.inside, 1, -1));
    return children1;
  }

  List<Widget> circlesOutside() {
    var children1 = <Widget>[];
    children1.addAll(circles(Colors.red, Touch.outside, 0, -1));
    children1.addAll(circles(Colors.red, Touch.outside, -1, 0));
    children1.addAll(circles(Colors.red, Touch.outside, 0, 1));
    children1.addAll(circles(Colors.red, Touch.outside, 1, 0));
    children1.addAll(circles(Colors.blue, Touch.outside, -1, -1));
    children1.addAll(circles(Colors.blue, Touch.outside, -1, 1));
    children1.addAll(circles(Colors.blue, Touch.outside, 1, 1));
    children1.addAll(circles(Colors.blue, Touch.outside, 1, -1));
    return children1;
  }

  List<Widget> circlesWithOffset() {
    var children2 = <Widget>[];
    children2.addAll(circles(Colors.purple, Touch.outside, 0, -1, dx: -15, dy: 15));
    children2.addAll(circles(Colors.purple, Touch.outside, -1, 0, dx: -15, dy: 15));
    children2.addAll(circles(Colors.purple, Touch.outside, 0, 1, dx: -15, dy: 15));
    children2.addAll(circles(Colors.purple, Touch.outside, 1, 0, dx: -15, dy: 15));
    children2.addAll(circles(Colors.green, Touch.inside, 0, -1, dx: -15, dy: 15));
    children2.addAll(circles(Colors.green, Touch.inside, -1, 0, dx: -15, dy: 15));
    children2.addAll(circles(Colors.green, Touch.inside, 0, 1, dx: -15, dy: 15));
    children2.addAll(circles(Colors.green, Touch.inside, 1, 0, dx: -15, dy: 15));

    return children2;
  }

  List<Widget> circles(
    Color color,
    Touch touch,
    int dirX,
    int dirY, {
    double dx,
    double dy,
    double moveByChildWidth,
    double moveByChildHeight,
  }) {
    return <Widget>[
      alignPositionedCircle(
          0.0, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.1, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.2, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.3, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.4, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.5, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.6, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.7, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.8, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          0.9, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
      alignPositionedCircle(
          1.0, color, dirX, dirY, touch, dx, dy, moveByChildWidth, moveByChildHeight),
    ];
  }

  List<Widget> circlesWithNamedAlignments() {
    return <Widget>[
      AlignPositioned(
          child: circle(Colors.orange), alignment: Alignment.center, touch: Touch.inside),
      AlignPositioned(
          child: circle(Colors.orange), alignment: Alignment.center, touch: Touch.outside),

      //
      AlignPositioned(
          child: circle(Colors.green), alignment: Alignment.centerRight, touch: Touch.inside),
      AlignPositioned(
          child: circle(Colors.green), alignment: Alignment.bottomCenter, touch: Touch.inside),
      AlignPositioned(
          child: circle(Colors.green), alignment: Alignment.centerLeft, touch: Touch.inside),
      AlignPositioned(
          child: circle(Colors.green), alignment: Alignment.topCenter, touch: Touch.inside),
      //
      AlignPositioned(
          child: circle(Colors.blue), alignment: Alignment.topRight, touch: Touch.inside),
      AlignPositioned(
          child: circle(Colors.blue), alignment: Alignment.bottomRight, touch: Touch.inside),
      AlignPositioned(
          child: circle(Colors.blue), alignment: Alignment.topLeft, touch: Touch.inside),
      AlignPositioned(
          child: circle(Colors.blue), alignment: Alignment.bottomLeft, touch: Touch.inside),
      //
      AlignPositioned(
          child: circle(Colors.red), alignment: Alignment.centerRight, touch: Touch.outside),
      AlignPositioned(
          child: circle(Colors.red), alignment: Alignment.bottomCenter, touch: Touch.outside),
      AlignPositioned(
          child: circle(Colors.red), alignment: Alignment.centerLeft, touch: Touch.outside),
      AlignPositioned(
          child: circle(Colors.red), alignment: Alignment.topCenter, touch: Touch.outside),
      //
      AlignPositioned(
          child: circle(Colors.purple), alignment: Alignment.topRight, touch: Touch.outside),
      AlignPositioned(
          child: circle(Colors.purple), alignment: Alignment.bottomRight, touch: Touch.outside),
      AlignPositioned(
          child: circle(Colors.purple), alignment: Alignment.topLeft, touch: Touch.outside),
      AlignPositioned(
          child: circle(Colors.purple), alignment: Alignment.bottomLeft, touch: Touch.outside),
    ];
  }

  AlignPositioned alignPositionedCircle(
    double mult,
    Color color,
    int dirX,
    int dirY,
    Touch touch,
    double dx,
    double dy,
    double moveByChildWidth,
    double moveByChildHeight,
  ) {
    return AlignPositioned(
        child: circle(color),
        alignment: Alignment(mult * dirX, mult * dirY),
        touch: touch,
        dx: dx,
        dy: dy,
        moveByChildWidth: moveByChildWidth,
        moveByChildHeight: moveByChildHeight);
  }

  Container circle(Color color, [double diameter = 30.0]) {
    return Container(
        width: diameter,
        height: diameter,
        decoration: BoxDecoration(
          border: Border.all(width: 1.0, color: Colors.black),
          color: color,
          shape: BoxShape.circle,
        ));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  align_positioned: ^1.1.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:align_positioned/align_positioned.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Aug 24, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/align_positioned.dart.

Run flutter format to format lib/align_positioned.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
matrix4_transform ^1.0.1 1.0.2
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test