How to position in the Flutter Stack layout

Foreword

Want to record the two ways of positioning in the Stack layout.

Code


//... omit extraneous code...

child: new Column(
          children: <Widget>[
            new SizedBox(height: 20.0),
            new Stack(
                             Alignment: const FractionalOffset(0.9, 0.1), // Method 1
              children: <Widget>[
                new Image(
                  image: new AssetImage("assets/images/illustration_11.jpg"),
                  width: 300.0,
                  height: 200.0,
                  fit: BoxFit.cover,
                ),
                new Opacity(
                  opacity: 0.8,
                  child: new Image(
                    image: new AssetImage("assets/images/illustration_12.jpg"),
                    width: 200.0,
                    height: 150.0,
                    fit: BoxFit.cover,
                  ),
                ),
                new GestureDetector(
                  onTap: () {
                                         Fluttertoast.showToast (msg: "Share it");
                  },
                  child: new Icon(Icons.share, color: Colors.white),
                ),
              ],
            ),
            new SizedBox(height: 20.0),
            new Stack(
              children: <Widget>[
                new Image(
                  image: new AssetImage("assets/images/illustration_11.jpg"),
                  width: 300.0,
                  height: 200.0,
                  fit: BoxFit.cover,
                ),
                                 New Positioned (/ / method two
                  right: 15.0,
                  top: 15.0,
                  child: new Icon(
                    Icons.share,
                    color: Colors.white,
                  ),
                ),
              ],
            )
          ],
        ),
        
                 //... omit extraneous code...

method one

Use alignment with FractionalOffset: For the parameters of the FractionalOffset, I understand this: the equivalent ratio, the first one represents the horizontal weight, the second represents the vertical weight, the horizontal 0.9 represents the position of nine out of the horizontal, and the vertical 0.1 represents the vertical To one tenth of the position

Method Two

Use the positioning component Positioned, top, right, buttom, left, directly represent the distance from the direction

effect

image

Intelligent Recommendation

[Flutter component] Stack layout Stack, PositiveED

Layer layout (stack) and Web Absolute positioning,Android middle FrameLayout The layout is similar, and the sub -module can determine its own position according to the position of the four corners of ...

Flutter layout (eight) - Stack, IndexedStack, GridView

This article mainly introduces the Stack, IndexedStack, and GridView controls in the Flutter layout. It introduces its layout behavior and usage scenarios in detail, and analyzes the source code. 1. S...

Flutter - Stack layout widgets to achieve results

The combination of Stack and Positioned is used to achieve the following page layout effects:  ...

Flutter basis of Stack Layout Widgets Comments

Outline Stack components is a stacked arrangement, i.e., covering another component assembly, in order to cover dependschildrenPlaced in the order, such as on the image scene using add some text, so t...

Flutter Stack frame layout, lamination stacking

Flutter Stack frame layout, lamination stacking Image stacked together two...

More Recommendation

Stack and Positioned components of Flutter layout components

Stacked layout Stack, Positioned The stacked layout is similar to the absolute positioning in the Web and the Frame layout in Android. The child component can determine its position according to the p...

Stack cascading component of Flutter page layout

Stack represents the meaning of heap, we can use Stack or combine Align or Positond to achieve positioning layout Stack common attributes: Attributes Description alignment Configure the display positi...

Flutter basic layout Widgets stack detailed explanation

Overview The Stack component is a stacked layout, that is, the component covers another component, and the order of coverage depends on thechildrenThe order of placement in the use scenario, such as a...

flutter Flex Wrap Stack Align layout

1. flex layout: Flex( direction: Axis.horizontal, //Horizontal reverse (direction cannot be empty) direction: Axis.vertical, //Vertical reverse Expanded( flex: 1 ) ) The implementation code is as foll...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top