当前位置:网站首页>Container of the basic component of the flutter
Container of the basic component of the flutter
2022-06-29 10:01:00 【Mr beast no beast】
In the official profile , say Container Component is a convenient drawing 、 Components that locate and resize subcomponents .
First Container Will be in child Fill around the sub assembly padding( Include decoration Existing in border), And then according to the constraints constraints To determine the width and height of the sub assembly , Last Container Will be based on margin To add white space around .
In the process of drawing ,Container First, I will apply matrix transformation transform, Then draw decoration, Then draw child Child components , Finally draw foregroundDecoration.
Container Try to be as large as possible if there are no sub components , Unless the incoming constraint constraints It's infinite , If that's the case ,Container As small as possible .Containers with children size themselves to their children. The width, height, and constraints arguments to the constructor override this.( I can't understand this sentence ,T_T).
in general ,Container Is a very common component , We can use it to wrap any component , I said before Text The components have backgroundColor It will cause some text display problems , If you use Container To the parcel Text Setting the background is very convenient , And the styles including fillet can be set easily , No more Android That defines many of the same things xml 了 .
1 Construction method
Container({Key key, AlignmentGeometry alignment, EdgeInsetsGeometry padding, Color color, Decoration decoration, Decoration foregroundDecoration, double width, double height, BoxConstraints constraints, EdgeInsetsGeometry margin, Matrix4 transform, Widget child })
Container There is only one constructor , There are no parameters that must be passed , But we usually use it to wrap sub components , That is, it is generally set child attribute .
2 Common properties
width and height: Width and height , This one doesn't need to be repeated .
color: Background color , It's worth one Color object , Cannot be associated with decoration Property is set at the same time .
margin: Margin , It's worth one EdgeInsets object .EdgeInsets Object to call EdgeInsets.all() Methods to uniformly set the margins of the four edges at the top left and bottom right , You can also call EdgeInsets.fromLTRB() Set the margins of the upper left and lower right sides respectively .
padding: Internal spacing , Value with margin.
alignment: Alignment mode , Optional value ( It's easy to understand from the literal meaning ) Yes :
Alignment.topLeft: Align vertically to the top and horizontally to the left .
Alignment.topCenter: Align vertically to the top and horizontally to the center .
Alignment.topRight: Align vertically to the top and horizontally to the right .
Alignment.centerLeft: Align vertically and horizontally to the left .
Alignment.center: Align vertically and horizontally .
Alignment.centerRight: Vertically centered, horizontally right aligned .
Alignment.bottomLeft: Align vertically to the bottom and horizontally to the left .
Alignment.bottomCenter: Align vertically to the bottom and horizontally to the center .
Alignment.bottomRight: Align vertically to the bottom and horizontally to the right .
In addition to the constants above , You can also create Alignment Object designation x、y Offset .
decoration: decorate , Background border, etc , Cannot be associated with color Property is set at the same time , Will be drawn in child under , That is, it will be child Cover , Specifically API Reference resources 2.1
BoxDecoration.
foregroundDecoration: It's also decoration , But it will be drawn in child above , That is, it will cover child.
constraints: constraint , This rule seems very complicated , We will study it in detail later .
transform: Shape change , This should be used less , May be used in animation , We will study it in detail later .
child: Child components .
2.1 BoxDecoration
First BoxDecoration It's just Decoration An implementation class , Other implementation classes are FlutterLogoDecoration、ShapeDecoration、UnderlineTabIndicator, Here is just an introduction to the commonly used BoxDecoration.
color: Background fill color , It's worth one Color object .
border: It's worth one BoxBorder object , This object can set the border color 、 Border width 、 Border styles, etc .
borderRadius: Border fillet , You can call BorderRadius.all() Set the rounded corners of the four corners uniformly , You can also call BorderRadius.only() Set the fillets of the four corners respectively .
gradient: Set as the background of gradient effect , Will be covered color.
boxShadow: shadows , It's worth one BoxShadow aggregate .
backgroundBlendMode: It should be background blending mode , This should be complicated , I'll study it later .
image: Use pictures as decorations .
The following is a with the above properties set demo:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var imgUrl =
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1545122324077&di=1b5986ad937c81c41f4c135ea1a9a026&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fzhidao%2Fwh%253D450%252C600%2Fsign%3Df719f9458f01a18bf0be1a4bab1f2b3e%2Fc2fdfc039245d688a8f2cdcdacc27d1ed31b24e2.jpg";
return MaterialApp(
// Whether or not shown debug label
debugShowCheckedModeBanner: false,
title: "Container",
home: Scaffold(
appBar: new AppBar(
title: new Text("Container"),
),
body: new Container(
// color: new Color(0xFFFF0000),
// Margin , It's worth one EdgeInsets object
margin: EdgeInsets.all(30.0),
// Internal spacing , It's worth one EdgeInsets object
padding: EdgeInsets.fromLTRB(30.0, 0, 0, 0),
// Alignment mode , Optional values are :
//Alignment.topLeft: Align vertically to the top and horizontally to the left .
//Alignment.topCenter: Align vertically to the top and horizontally to the center .
//Alignment.topRight: Align vertically to the top and horizontally to the right .
//Alignment.centerLeft: Align vertically and horizontally to the left .
//Alignment.center: Align vertically and horizontally .
//Alignment.centerRight: Vertically centered, horizontally right aligned .
//Alignment.bottomLeft: Align vertically to the bottom and horizontally to the left .
//Alignment.bottomCenter: Align vertically to the bottom and horizontally to the center .
//Alignment.bottomRight: Align vertically to the bottom and horizontally to the right .
// In addition to the constants above , You can also create Alignment Object designation x、y Offset
alignment: Alignment.centerLeft,
// decorate , Background border, etc , Cannot be associated with color Property is set at the same time , Will be drawn in child under , That is, it will be child Cover
decoration: new BoxDecoration(
// Background fill color
color: new Color(0xFFFF0000),
// Background border
border: new Border.all(
// Border color
color: new Color(0xFFFFFF00),
// Border width
width: 5),
// Border fillet
borderRadius: new BorderRadius.only(
topLeft: new Radius.circular(5.0),
topRight: new Radius.circular(10.0),
bottomLeft: new Radius.circular(15.0),
bottomRight: new Radius.circular(20.0)),
// Gradient effect , Will be covered color
gradient: new LinearGradient(colors: [
new Color(0xFFFFDEAD),
new Color(0xFF98FB98),
new Color(0xFF6495ED)
]),
// shadows
boxShadow: [new BoxShadow(color:Color(0xFFFF0000),blurRadius: 5.0)],
// It should be background blending mode , This should be complicated , I'll study it later
backgroundBlendMode: BlendMode.color,
// picture
// image: new DecorationImage(image: new NetworkImage(imgUrl))
),
// It's also decoration , But it will be drawn in child above , That is, it will cover child
// foregroundDecoration: new BoxDecoration(
// image: new DecorationImage(image: new NetworkImage(imgUrl))
// ),
// constraint , This rule seems very complicated , We will study it in detail later
constraints: new BoxConstraints(maxWidth: 300.0, maxHeight: 400.0),
// Shape change , This should be used less , May be used in animation , We will study it in detail later
transform: new Matrix4.skewY(0.3),
// Child components
child: new Text(
"Hello World",
textDirection: TextDirection.ltr,
style: new TextStyle(color: new Color(0xFFFFFFFF), fontSize: 40.0),
),
),
),
);
}
}
The operation effect is as follows :

You can see that we give Container Set up margin attribute , So there are some outer margins up, down, left and right , Then although the alignment is set alignment by centerLeft, But the left margin is set to 100, All the left side has some inner space , Constraints are also set constraints The maximum width is 300, So its width is smaller than the full screen minus the outer margin , We also set the border 、 Round corners 、 Gradient background 、 Matrix transformation and a series of attributes that make it more effective , These settings are not troublesome , The final result is the above effect .
3 summary
I'm learning Text When you set the component, you don't know how to set the rounded background , But if you use Container A package is simply not too simple , and Flutter Rounded corners are implemented in a way that compares to Android That kind of writing a lot xml How to file , Let me fall in love with it .
边栏推荐
- 数据库常见面试题(附答案)
- 遍历vector容器中的对象的方式
- 证券账号开户安全吗?是靠谱的吗?
- Implementation of multi key state machine based on STM32 standard library
- Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning
- Making of simple addition calculator based on pyqt5 and QT Designer
- Introduction to Chang'an chain data storage and construction of MySQL storage environment
- Generic paging framework
- leetcode MYSQL数据库题目180
- linux环境下安装配置redis,并设置开机自启动
猜你喜欢

Segmentation of Head and Neck Tumours Using Modified U-net

Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.

装饰器模式的应用,包装ServletRequest,增加addParameter方法

How to traverse objects in the vector container

Flutter 基础组件之 Image

CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION

Zabbix4.4 configure the indicators of the monitoring server and solve the garbled graphics pages

Custom MVC framework implementation

完美二叉树、完全二叉树、完满二叉树

Chang'an chain go language smart contract writing and compilation
随机推荐
Official STM32 chip package download address stm32f10x stm32f40x Download
Monitoring data source connection pool usage
Es error nonodeavailableexception[none of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
分布式和集群分不清,我们讲讲两个厨子炒菜的故事
Leetcode MySQL database topic 181
微信小程序重写Page函数,实现全局日志记录
mysql修改自动递增初始值
C语言中通过sprintf()函数构造sql语句
Cloud management platform: openstack architecture design and detailed interpretation
监控数据源连接池使用情况
Leetcode MySQL database topic 180
ImageView图片填充问题
Student增删gaih
通用分页框架
zabbix4.4配置监控服务器指标,以及图形页乱码解决
JVM之方法的绑定机制
leetcode MYSQL数据库题目177
安装Anaconda后启动JupyterLab需要输入密码
Custom MVC framework implementation
Perfect binary tree, complete binary tree, perfect binary tree