自定义的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. 14.1 Socket 套接字编程入门

    Winsock是Windows操作系统上的套接字API,用于在网络上进行数据通信.套接字通信是一种允许应用程序在计算机网络上进行实时数据交换的技术.通过使用Windows提供的API,应用程序可以创建 ...

  2. 关于 React 性能优化和数栈产品中的实践

    我们是袋鼠云数栈 UED 团队,致力于打造优秀的一站式数据中台产品.我们始终保持工匠精神,探索前端道路,为社区积累并传播经验价值. 本文作者:的卢 引入 在日常开发过程中,我们会使用很多性能优化的 A ...

  3. Mybatis-plus 生成代码

    引入依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-g ...

  4. ThreadPoolExecutor使用浅谈

    1. 基础介绍 ThreadPoolExecutor是Python标准库concurrent.futures模块中的一个类,用于实现线程池的功能. ThreadPoolExecutor模块相比于thr ...

  5. 基于亚博k210+arduino 智能垃圾桶(23工训赛)

    #2023 10 15 派大星改 # object classifier boot.py # generated by maixhub.com from fpioa_manager import * ...

  6. 《最新出炉》系列初窥篇-Python+Playwright自动化测试-28-处理日历时间控件-上篇

    1.简介 我们在实际工作中,有可能遇到有些web产品,网页上有一些时间选择,然后支持按照不同时间段范围去筛选数据,例如:我们预定火车票或者预定酒店,需要选择发车日期或者酒店的入住与退房时间.宏哥早在之 ...

  7. [NOIP 考前备战] 线段树刷题

    备战线段树 T1 AcWing .1275. 最大数 查询最大值 + 单点修改 #include <bits/stdc++.h> #define int long long using n ...

  8. Modbus转Profinet 网关

    产品简介 实现 PROFINET 网络与串口网络之间的数据通信,三个串口可分别连接具有 RS232 或 RS485 接口的设 备到 PROFINET 网络.即将串口设备转换为 PROFINET 设备. ...

  9. 方法覆盖Override

    继承作用: 基本作用:代码复用 重要作用:方法覆盖和多态机制 ===================================================================== ...

  10. 【报错:For input string: ""报错: get connection error! 报错:java.lang.NullPointerException 报错:java.lang.NumberFormatException: For input string: "id"】解决方案

    原因:没有input数据进入,但是当我填写数据进入的时候 get connection error! 这个消息,是我要抛出去的异常,源代码下 我一开始觉得是代码书写的问题,找.......... 应该 ...