当前位置:网站首页>[shutter -- layout] flexible layout (flex and expanded)
[shutter -- layout] flexible layout (flex and expanded)
2022-07-23 19:09:00 【Kevin-Dev】

List of articles
Preface
Flutter The elastic layout in is mainly through Flex and Expanded To achieve .
This article mainly introduces Flutter Medium Flex Layout .
Flex
1. brief introduction
Flex Component can arrange its subcomponents horizontally or vertically , If you know the direction of the spindle , Use Row or Column It will be more convenient , because Row and Column Inherit from Flex, The parameters are basically the same , So you can use Flex Basically, all the places can be used Row or Column .
2. attribute
Flex Common properties are as follows :
direction: Set the spindle direction , The settable value is Axis.horizontal and Axis.vertical, The cross axis is perpendicular to the spindle direction .
mainAxisAlignment: Setter Widget Arrangement along the main axis , Default MainAxisAlignment.start, The settings can be as follows :
- MainAxisAlignment.start: Align left , The default value is ;
- MainAxisAlignment.end: Right alignment ;
- MainAxisAlignment.center: Align center ;
- MainAxisAlignment.spaceBetween: full-justified ;
- MainAxisAlignment.spaceAround: Every Widget Equally spaced on both sides , The distance from the edge of the screen is other Widget Half the interval between ;
- MainAxisAlignment.spaceEvently: Average distribution of each Widget, The distance from the edge of the screen is the same as other Widget The intervals between are equal .

mainAxisSize: Set the size of the spindle , Default MainAxisSize.max, The values that can be set are as follows :
- MainAxisSize.max: The size of the spindle is the size of the parent container ;
- MainAxisSize.min: The size of the spindle is its capital Widget The sum of size .

take mainAxisAlignment Set to spaceBetween, If mainAxisSize Set to max, It's the whole Row On the basis of width, according to spaceBetween Arrange in a way , If mainAxisSize Set to min, Three Container The sum of the widths is in accordance with spaceBetween Arrange in a way .
crossAxisAlignment: Setter Widget The arrangement along the cross axis , Default CrossAxisAlignment.center, The settings can be as follows :
- CrossAxisAlignment.start: Align with the starting position of the cross axis ;
- CrossAxisAlignment.end: Align with the end of the cross axis ;
- CrossAxisAlignment.center: Align center ;
- CrossAxisAlignment.stretch: Fill the entire cross axis ;
- CrossAxisAlignment.baseline: Align according to the baseline of the first line of text .

verticalDirection: Sets the vertical direction of the child Widget The order of arrangement , The default is VerticalDirection.down, The setting method is as follows :
- VerticalDirection.down:start At the top ,end At the bottom ;
- VerticalDirection.up:start At the bottom ,end At the top .

textBaseline: Sets the baseline type for text alignment , The values that can be set are as follows :
- TextBaseline.alphabetic: Align with the letter baseline ;
- TextBaseline.ideographic: Align with ideographic baseline ;
Expanded
Expanded It can be scaled or expanded Row、Column and Flex The amount of space occupied by the subcomponent .
1. attribute
key
It's a unique identifierflex
Coefficient of elasticity
If 0 or null, be child There is no flexibility , That is, the space that will not be occupied by expansion .
If it is greater than 0, be-all Expanded According to it flex The proportion of the spindle to divide all the free space .
example
1. design sketch

2. Code example
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({
Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text(' Elastic layout '),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flex(
direction: Axis.horizontal,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
color: Colors.pink,
child: FlutterLogo(
size: 50.0,
),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.green,
child: FlutterLogo(
size: 50.0,
),
),
),
],
),
Padding(
padding: EdgeInsets.only(top: 20.0),
child: SizedBox(
height: 100.0,
child: Flex(
direction: Axis.vertical,
children: <Widget>[
Expanded(
flex: 2,
child: Container(
height: 30.0,
color: Colors.blue,
),
),
Spacer(
flex: 1,
),
Expanded(
flex: 1,
child: Container(
height: 30.0,
color: Colors.green,
),
),
],
),
),
)
],
),
)
)
);
}
}
边栏推荐
- Time2Vec 的理解与简单实现
- JUC concurrent programming [detailed explanation and demonstration]
- Source code analysis of ThreadPoolExecutor
- .NET Core 实现后台任务(定时任务)Longbow.Tasks 组件(三)
- LM393 low power dual voltage comparator parameters, pins, application details
- 一、爬虫概念及基本流程
- Learn and understand Architecture Design from business development
- 11. Basic concepts of neural network
- 手写bind、call、apply其实很简单
- 1、 Reptile concept and basic process
猜你喜欢
![[2020] [paper notes] Based on Rydberg atom——](/img/5c/186cae4e47a236ae4062d15f839196.png)
[2020] [paper notes] Based on Rydberg atom——
![Multithreading [comprehensive study of graphics and text]](/img/70/8a1227b2159349cf25a85dff8f9d1c.png)
Multithreading [comprehensive study of graphics and text]
![Redis [2022 latest interview question]](/img/32/7efbc52f97eb3be90c7fa2e6863758.png)
Redis [2022 latest interview question]

Completion report of communication software development and Application

1259. Disjoint handshake dynamic programming

FPGA implementation of IIC bus of IIC protocol (II) (single read / write drive)

FPGA基于spi的flash读写

What is stack and the difference between stacks

多线程【全面学习 图文精讲】

LeetCode 剑指 Offer II 115.重建序列:图解 - 拓扑排序
随机推荐
How can win11 add 3D effects to pictures? Win11 method of adding picture 3D effect
Clean code and efficient system method
The original path is not original [if there is infringement, please contact the original blogger to delete]
C#启动程序传递参数丢失双引号,如何解决?
Fragment
Terminal command (all)
MQ [messagequeue graphic explanation and four MQ comparisons]
【ONNX】动态输入尺寸的问题(多输出/多输入)
1259. Disjoint handshake dynamic programming
Crack WiFi password with Kail
Gradle [graphic installation and use demonstration]
电子元件-电阻
Cell array processing
TCL scripting language foundation (2)
【论文阅读】GETNext: Trajectory Flow Map Enhanced Transformer for Next POI Recommendation
[attack and defense world web] difficulty Samsung 9-point introductory question (end): Fakebook, favorite_ number
11.神经网络基本概念
LM393 low power dual voltage comparator parameters, pins, application details
Emgucv common function function description "suggestions collection"
It's too strong. An annotation handles the data desensitization returned by the interface