当前位置:网站首页>[shutter -- layout] detailed explanation of the use of align, center and padding
[shutter -- layout] detailed explanation of the use of align, center and padding
2022-07-26 09:19:00 【Kevin-Dev】

List of articles
This paper mainly introduces Flutter In the layout Padding 、Align as well as Center Control .
Align
1. brief introduction
Development at other ends ,Align Generally, it is regarded as the property of a control , It is not taken out as a separate control .Align The functions implemented by itself are not complex , Set up child The alignment of , For example, center 、 On the left, on the right, etc , And according to child Adjust your own size .
2. attribute
alignment: Alignment mode , Generally, the system default 9 Ways of planting , But it's not the only thing 9 Kind of , For example, the following definitions . The system provides 9 The two ways are only pre-defined .
widthFactor: Width factor , If set ,Align The width of is child Multiply the width of by this value , It can't be negative .
heightFactor: Height factor , If set ,Align The height of child Multiply the height of by this value , It can't be negative .
3. example
1. design sketch 
2. Code
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('Align'),
),
body: Container(
height: 120.0,
width: 120.0,
color: Colors.blue.shade50,
child: Align(
alignment: Alignment.topRight,
child: FlutterLogo(
size: 60,
),
),
)
)
);
}
}
Center
1. brief introduction
Center Inherited from Align, It's just that alignment Set to Alignment.center, Other properties such as widthFactor、heightFactor, Layout behavior , Both with Align Exactly the same as , Here is no longer a separate introduction .Center Source code is as follows , No settings alignment attribute , Because Align The default alignment is centered .
class Center extends Align {
/// Creates a widget that centers its child.
const Center({
Key key, double widthFactor, double heightFactor, Widget child })
: super(key: key, widthFactor: widthFactor, heightFactor: heightFactor, child: child);
}
Padding
1. brief introduction
Padding stay Flutter There are also many in use , As a basic control , Very single function , Set... For child nodes padding attribute . Anyone who has written about other terminals knows this attribute , Is to set the inner margin property , A blank area in the inner margin , It's also widget Part of .
2. attribute
padding:padding The type of EdgeInsetsGeometry,EdgeInsetsGeometry yes EdgeInsets as well as EdgeInsetsDirectional Base class of . Internationalization is not involved in practical use , For example, it is suitable for the Arab region , It's generally used EdgeInsets.EdgeInsetsDirectional Just look at the naming, you can know that it is related to the direction , Therefore, its four margins are not limited to up, down, left and right , It depends on the direction .
3. Sample code
new Padding(
padding: new EdgeInsets.all(8.0),
child: const Card(child: const Text('Hello World!')),
)
边栏推荐
猜你喜欢

Zipkin installation and use

优秀的 Verilog/FPGA开源项目介绍(三十零)- 暴力破解MD5

Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world

Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain

Redis principle and usage - installation and distributed configuration

李沐d2l(五)---多层感知机

CF1481C Fence Painting

Ext4 file system opens dir_ After nlink feature, link_ Use link after count exceeds 65000_ Count=1 means the quantity is unknown

十大蓝筹NFT近半年数据横向对比

OFDM 十六讲- OFDM
随机推荐
Processing of inconsistent week values obtained by PHP and MySQL
Vertical search
优秀的 Verilog/FPGA开源项目介绍(三十零)- 暴力破解MD5
JS - DataTables control on the number of displays per page
Study notes of dataX
李沐d2l(四)---Softmax回归
redis原理和使用-基本特性
Study notes of canal
Li Mu D2L (V) -- multilayer perceptron
[online problem] timeout waiting for connection from pool problem troubleshooting
[MySQL] detailed explanation of redo log, undo log and binlog (4)
聪明的美食家 C语言
Clean the label folder
JS - DataTables 关于每页显示数的控制
When you click input, the border is not displayed!
Hbuilderx runs the wechat developer tool "fail to open ide" to solve the error
“could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32” 问题处理
字节缓冲流&字符流详解
Zipkin安装和使用
(2006,Mysql Server has gone away)问题处理