当前位置:网站首页>[shutter -- layout] basic use of container
[shutter -- layout] basic use of container
2022-07-21 06:59:00 【Kevin-Dev】
List of articles
One 、 brief introduction
Container
stay Flutter It's very common in . Official profile , Is a combination of drawing (painting
)、 location (positioning
) And size (sizing
)widget
Of widget
.
You can get a few messages , It's a combination widget
, There are drawings inside widget
、 location widget
、 Size widget
. I saw a lot later widget
, Through some more basic widget
Combined .
1. effect
Used to place widget
The container of , Yes padding
、margin
、 Location 、 Size equal parameter
- The most commonly used default layout ! Only one can be included
child
:, The supporting configurationpadding,margin,color
, Wide and high ,decoration
( Generally configure borders and shadows ) Other configuration , - stay Flutter in , Not all controls have Wide and high 、
padding、margin、color
Equal attribute , So there isPadding、Center
etc.Widget
.
2. attribute
key:
Container
Unique identifier , Used to find updates .alignment: control
child
The alignment of , Ifcontainer
perhapscontainer
The parent node size is larger thanchild
The size of the , This property setting will work , There are many kinds of alignment .padding:
decoration
A blank area inside , If there ischild
Words ,child
be locatedpadding
Inside .padding
Andmargin
The difference is that ,padding
Is contained incontent
Inside , andmargin
It's the outer boundary , To set the click event ,padding
The area will respond , andmargin
The area will not respond .color: Used to set
container
Background color , IfforegroundDecoration
Set it up , May cover up color effect .decoration: Draw on
child
The back decoration , Set updecoration
Words , You can't set color attribute , Otherwise, an error will be reported , It should be atdecoration
Set the color in .foregroundDecoration: Draw on child The front decoration .
width:
container
Width , Set todouble.infinity
It can be forced to fill the width , Not set up , According to child Layout with both parent nodes .height:
container
Height , Set todouble.infinity
Can be forced to fill up at height .constraints: Add to
child
On additional constraints .margin: Around
decoration
andchild
A blank area outside , Not part of the content area .transform: Set up
container
The transformation matrix of , The type isMatrix4
.child:
container
The content inwidget
.
3. Use scenarios
Container In the current project , The one most often used widget . In actual use , It will be used in the following cases Container, Of course, it's not absolute , It can also be done through other widget To achieve .
- The interval needs to be set ( In this case , If it's just a simple interval , It can also be done through Padding To achieve );
- You need to set the background color ;
- When you need to set rounded corners or borders (ClipRRect You can also achieve the fillet effect );
- Need alignment (Align It can also be realized );
- When you need to set the background picture ( You can also use Stack Realization ).
Two 、 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('Container Basic use of '),
),
body: Container (
constraints: BoxConstraints.expand(
height: Theme.of(context).textTheme.headline4!.fontSize! * 1.1 + 200,
),
decoration: BoxDecoration(
border: Border.all(width: 2.0,color: Colors.red),
color: Colors.grey,
borderRadius: BorderRadius.all(Radius.circular(20.0)),
image: DecorationImage(
image: AssetImage("images/avatar.png"),
centerSlice: Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0)
),
),
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text('Hello Kevin',
style: Theme.of(context).textTheme.displayMedium!.copyWith(color: Colors.black)),
transform: Matrix4.rotationZ(0.3),
)
)
);
}
}
边栏推荐
- 使用EasyExcel进行读写操作
- 鸿蒙HarmonyOS 3官宣:7月27日正式发布;苹果2023年放缓部分团队招聘和支出;俄罗斯对谷歌重罚26亿元|极客头条...
- Flink memory model of Flink series: analyze the memory management of Flink from the perspectives of macro (Flink memory model), micro (Flink memory structure), data transmission, etc
- [go open source treasure] performance tuning skills based on golang syntax (array traversal)
- 【线性DP】数字三角形
- Notes....
- 国内外知名源码商城系统盘点
- golang--操作日期
- Windows Server 2022获7月非安全更新:修复因Defender导致的卡死问题
- Global location number Gln application introduction
猜你喜欢
uni-app开发之HBuilderX连接夜神模拟器
Notes....
iptables :chains, target
Delegation mechanism of simplified governance of Dao
打造数据驱动型组织,成长型企业最需要什么?
Understand what configuration center is?
【LeetCode】2. 两数相加 - Go 语言题解
鸿蒙HarmonyOS 3官宣:7月27日正式发布;苹果2023年放缓部分团队招聘和支出;俄罗斯对谷歌重罚26亿元|极客头条...
Pyspark:DataFrame的转化操作及行动操作
《运营商数据存力指标》发布,透露了哪些重要趋势?
随机推荐
Highlight first! 2022 open atom global open source summit is scheduled to be held in Beijing on July 25-29
Huawei computer test: Student matrix
ARM 如果通过笔记本机上外网?
AWD思路
加密市场中的14个心智模型
去掉<li>前面空白距离
网络 与vpc实验
亮点抢先看!2022 开放原子全球开源峰会定于 7 月 25-29 日在北京举办
【Flutter -- 基础组件】按钮组件 - ElevatedButton、TextButton、OutlinedButton、IconButton
Notes....
轻松与劳氏Lowe’s 对接 EDI 要准备什么?
【Flutter -- 顶部导航栏】TabBarView 的基本使用
笔记。。。。
EasyGBS切换分辨率出现花屏和播放失败的原因分析及解决方法
Understand what configuration center is?
Video analysis streameye studio
【Flutter -- 基础组件】文本组件 Text & TextStyle & TextSpan
【Flutter -- 基础组件】AppBar 的使用
使用EasyExcel进行读写操作
【LeetCode】2. 两数相加 - Go 语言题解