当前位置:网站首页>[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,
),
),
],
),
),
)
],
),
)
)
);
}
}
边栏推荐
- 基于FPGA的SPI通讯协议实现
- Opencv (13): brief introduction to cv2.findcontours, cv:: findcontours and description of cv2.findcontours function in various versions of opencv
- FPGA基于spi的flash读写
- It's too strong. An annotation handles the data desensitization returned by the interface
- Learn about spark project on nebulagraph
- 【ONNX】动态输入尺寸的问题(多输出/多输入)
- 398. Random number index hash table method
- 迷宫类dp整合
- SQL statement exercise
- Leetcode 0131. split palindrome string
猜你喜欢

多线程&高并发(全网最新:面试题+导图+笔记)面试手稳心不慌

1259. 不相交的握手 动态规划

@JPA annotation in entity

Completion report of communication software development and Application

FPGA实现IIC协议(一)IIC总线协议

Learn about spark project on nebulagraph

Navigation component of jetpack compose uses

Redis【2022最新面试题】
![[heavyweight] focusing on the terminal business of securities companies, Borui data released a new generation of observable platform for the core business experience of securities companies' terminals](/img/28/8d9f33ad6f54d6344429a687a7d1d7.png)
[heavyweight] focusing on the terminal business of securities companies, Borui data released a new generation of observable platform for the core business experience of securities companies' terminals

Jetpack Compose之Navigation组件使用
随机推荐
Perl语言简述
LeetCode 剑指 Offer II 115.重建序列:图解 - 拓扑排序
Moxa serial server model, moxa serial server product configuration instructions
11. Basic concepts of neural network
Understanding and simple implementation of time2vec
CTF misc learning summary "suggestions collection"
多线程与高并发day11
?前台传参的问题待确认
C # split usage, split split split string
PHP file lock lottery to prevent concurrency
Leetcode 0131. split palindrome string
[2018] [paper notes] graphene FET and [2] - Preparation and transfer of graphene
Brief introduction of Perl language
How to use quota
How can zero foundation self-study software testing? Ten year test Laoniao's strongest software test learning Roadmap
@JPA annotation in entity
JUC并发编程【详解及演示】
Jetpack Compose之Navigation组件使用
Rapid establishment of devstack cloud computing platform
.NET Core 实现后台任务(定时任务)Longbow.Tasks 组件(三)