自定义的IconContainer

void main() {
runApp(MaterialApp(
theme: ThemeData(primarySwatch: Colors.yellow),
home: Scaffold(
appBar: AppBar(title: const Text("这是导航栏")),
body: MyApp(),
)));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return IconContainer(Icons.ac_unit,color: Colors.yellow);
}
}
//自定义的IconContainer
class IconContainer extends StatelessWidget {
Color color;
IconData icon;
// IconContainer(this.icon ,{super.key,required this.color}); // 与下方效果一样
// IconContainer(this.icon ,{Key? key,required this.color}) : super(key: key);
IconContainer(this.icon ,{Key? key, this.color=Colors.red}) : super(key: key); //可传入颜色(也可以不用传入颜色)

@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center, //内容居中
color: color,
height: 200,
width: 200,
child: Icon(icon,size: 50,),
);
}
}

mainAxisAlignment 用于指定子组件在主轴(水平方向)上的对齐方式
  1. MainAxisAlignment.start(默认值):子组件将在主轴的起始位置对齐。

  2. MainAxisAlignment.end:子组件将在主轴的末尾位置对齐。

  3. MainAxisAlignment.center:子组件将在主轴的中心位置对齐。

  4. MainAxisAlignment.spaceBetween:子组件将会均匀地分布在主轴上,首个和最后一个子组件分别与 Row 的起始和末尾位置对齐。

  5. MainAxisAlignment.spaceAround:子组件将会均匀地分布在主轴上,子组件之间以及首个和最后一个子组件与 Row 的边界之间有相等的间距。

  6. MainAxisAlignment.spaceEvenly:子组件将会均匀地分布在主轴上,子组件之间和首个、最后一个子组件与 Row 的边界之间的间距都相等。

  7. MainAxisAlignment.spaceEvenly:子组件将会均匀地分布在主轴上,子组件之间和首个、最后一个子组件与 Row 的边界之间的间距都相等。

crossAxisAlignment 用于指定子组件在交叉轴(垂直方向)上的对齐方式(要有父容器)
  1. CrossAxisAlignment.start:子组件将在交叉轴的起始位置对齐。

  2. CrossAxisAlignment.end:子组件将在交叉轴的末尾位置对齐。

  3. CrossAxisAlignment.center(默认值):子组件将在交叉轴的中心位置对齐。

  4. CrossAxisAlignment.stretch:在交叉轴上拉伸子组件以匹配父容器的高度。

  5. CrossAxisAlignment.baseline:子组件将使用 textDecorationStyle 属性构建一个水平基线对齐。

Row 水平布局组件

class MyRow extends StatelessWidget {
const MyRow({super.key}); @override
Widget build(BuildContext context) {
return Container(
width: double.infinity, //无穷的
height: double.infinity,
color: Color.fromARGB(255, 7, 189, 158),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, //X轴
crossAxisAlignment:CrossAxisAlignment.center, //相对与Container(父盒子) Y轴
children: [
IconContainer(Icons.ac_unit,color: Colors.yellow), //自定义的方法
IconContainer(Icons.home_max,color: Color.fromARGB(255, 226, 12, 47)),
IconContainer(Icons.ac_unit,color: Color.fromARGB(255, 9, 31, 155)),
],
),
);
}
}

Column垂直布局组件

class MyColumn extends StatelessWidget {
// const MyColumn({super.key});
const MyColumn({Key? key}) : super(key: key); @override
Widget build(BuildContext context) {
return Container(
width: double.infinity, //无穷的
height: double.infinity,
color: Color.fromARGB(255, 7, 189, 158),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, // Y轴
crossAxisAlignment:CrossAxisAlignment.end, //相对与Container X轴
children: [
IconContainer(Icons.ac_unit,color: Colors.yellow),
IconContainer(Icons.home_max,color: Color.fromARGB(255, 226, 12, 47)),
IconContainer(Icons.ac_unit,color: Color.fromARGB(255, 9, 31, 155)),
],
),
);
}
}

double.infifinity 和double.maxFinite

double.infifinity 和double.maxFinite可以让当前元素的width或者height达到父元素的尺寸;
区别:

我想成为我的父母所允许的最大的(double.infinity)

一些小部件允许他们的孩子像他们想要的那样大。

9、线性布局(Row和Column)的更多相关文章

  1. Flutter 布局类组件:线性布局(Row和Column)

    前言 所谓线性布局,即指沿水平或垂直方向排布子组件.Flutter中通过Row和Column来实现线性布局,并且它们都继承自弹性布局(Flex). 接口描述 Row({ Key key, // 表示子 ...

  2. 12.Quick QML-QML 布局(Row、Column、Grid、Flow和嵌套布局) 、Repeater对象

    1.Row布局 Row中的item可以不需要使用anchors布局,就能通过行的形式进行布局. 并且item可以使用Positioner附加属性来访问有关其在Row中的位置及其他信息. 示例如下所示, ...

  3. Flutter 布局(七)- Row、Column详解

    本文主要介绍Flutter布局中的Row.Column控件,详细介绍了其布局行为以及使用场景,并对源码进行了分析. 1. Row A widget that displays its children ...

  4. 从头学Android之Android布局管理:LinerLayout线性布局

    LinerLayout线性布局: 这种布局方式是指在这个里面的控件元素显线性,我们可以通过setOrientation(int orientation)来指定线性布局的显示方式,其值有:HORIZON ...

  5. Android 线性布局(LinearLayout)相关官方文档 - 指南部分

    Android 线性布局(LinearLayout)相关官方文档 - 指南部分 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用 ...

  6. Android-RelativeLayout(相对布局)、LinearLayout(线性布局)

    RelativeLayout(相对布局):按照各子元素之间的位置关系完成布局. 定位:android:layout_above="@id/xxx" --将控件置于给定ID控件之上 ...

  7. Android-LinearLayout(线性布局)

    布局:Android为我们提供了一个View和ViewGroup子类的集合.ViewGroup类是View的子类,也被称为Layout布局,它提供了流式布局.线性布局等多种布局方式.View是绘制在屏 ...

  8. android—-线性布局

    android五大布局之线性布局. 1.线性布局的特点:各个子元素彼此连接,中间不留空白 而今天我们要讲解的就是第一个布局,LinearLayout(线性布局),我们屏幕适配的使用 用的比较多的就是L ...

  9. android学习之线性布局

    效图如下 移通152余继彪 该布局使用了线性布局完成 父布局为线性布局,黄色和灰色部分为水平的线性布局,剩余50%部分为水平线性布局,该布局中包含了两个垂直的线性布局分别占了三分之1和三分之二

  10. android开发------编写用户界面之线性布局

    一个好的应用程序离不开人性化的用户界面.在学习其他东西之前.理应先学习编写程序的布局(外观) 今天,我们就来学习android的UI布局----LinearLayout. LinearLayout,即 ...

随机推荐

  1. 形象描绘TCP三次握手和四次挥手

    一.TCP三次握手TCP 三次握手就好比两个人在街上隔着50米看见了对方,但是因为雾霾等原因不能100%确认,所以要通过招手的方式相互确定对方是否认识自己.形象描绘TCP三次握手和四次挥手 张三首先向 ...

  2. python第6章 学习笔记

    # 第6章 学习笔记## 简介 Python代码在执行时是按照自上向下顺序执行的. 通过流程控制语句,可以改变程序的执行顺序,也可以让指定的程序反复执行多次 流程控制语句分成两大类:条件判断语句,循环 ...

  3. mooc第五单元《管理组织》单元测试

    第五单元<管理组织>单元测试     返回 本次得分为:30.00/50.00, 本次测试的提交时间为:2020-08-30, 如果你认为本次测试成绩不理想,你可以选择 再做一次 . 1 ...

  4. Elasticsearch 6.8.6

    mac;centos;unix;  下载 wget  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.6. ...

  5. JDK、JRE、JVM三者介绍

    概念 JDK: Java Development Kit,java开发者工具. JRE: Java Runtime Enviroment,java运行时环境. JVM: Java Virtual Ma ...

  6. 我们又组织了一次欧洲最大开源社区活动,Hugging Face 博客欢迎社区成员发帖、Hugging Chat 功能更新!

    每一周,我们的同事都会向社区的成员们发布一些关于 Hugging Face 相关的更新,包括我们的产品和平台更新.社区活动.学习资源和内容更新.开源库和模型更新等,我们将其称之为「Hugging Ne ...

  7. ts 终于搞懂TS中的泛型啦! | typescript 入门指南 04

    大家好,我是王天~ 这篇文章是 ts入门指南系列中第四篇,主要讲解ts中的泛型应用,泛型在ts中是比较重要的概念,我花挺长时间才搞明白的,希望能帮助到大家 ~ ** ts 入门指南系列 ** Ts和J ...

  8. CSS色域、色彩空间、CSS Color 4新标准

    引言 近期,三大主流浏览器引擎均发布最新版本,支持W3C的CSS Color 4标准,包含新的取色方法color()和相应语法,可展示更多的色域及色彩空间,这意味着web端能展示更丰富更高清的色彩.虽 ...

  9. JavaScript:判断数据类型的四种方法

    JavaScript目前有两种数据类型:基本数据类型和引用数据类型. 基本数据类型:Undefined.Null.Boolean.String.Number.Symbol(ES6) 引用数据类型:Ob ...

  10. 拿到开发板需要做的事情 -- 配置Python环境

    1.查看系统时间 date -R 2.修改系统时间 windows上时间项目时间正常,Ubuntu16.04上时间错误 - 贾斯丁哔哔 - 博客园 (cnblogs.com) 3.安装pip3 sud ...