自定义的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: double.infinity,
width: double.infinity,
child: Icon(icon,size: 50,),
);
}
}
Flex 组件可以沿着水平或垂直方向排列子组件,如果你知道主轴方向,使用 Row 或 Column 会方便一
些,因为 Row 和 Column 都继承自 Flex ,参数基本相同,所以能使用Flex的地方基本上都可以使用
Row 或 Column 。 Flex 本身功能是很强大的,它也可以和 Expanded 组件配合实现弹性布局 。

水平弹性布局

(1)

class MyApp extends StatelessWidget {
const MyAPP({super.key}); @override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(flex: 2,child: IconContainer(Icons.ac_unit,color: Colors.yellow),//元素设置宽度没有效果
),
Expanded(flex: 2,child: IconContainer(Icons.home_max,color: Color.fromARGB(255, 226, 12, 47)),
),
Expanded(flex: 1,child: IconContainer(Icons.ac_unit,color: Color.fromARGB(255, 9, 31, 155)),
),
],
);
}
}

(2)

class HomePage2 extends StatelessWidget {
const HomePage2({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Flex(
// direction: Axis.vertical, // 垂直
direction: Axis.horizontal, //水平
children: [
Expanded(flex: 2, child: IconContainer(Icons.home, color: Colors.red)),
Expanded(
flex: 1,
child: IconContainer(Icons.search, color: Colors.orange),
)],
);
}}

垂直弹性布局

(1)

class MyRow extends StatelessWidget {
const MyRow({super.key}); @override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(flex: 2,child: IconContainer(Icons.ac_unit,color: Colors.yellow),//元素设置高度没有效果
),
Expanded(flex: 2,child: IconContainer(Icons.home_max,color: Color.fromARGB(255, 226, 12, 47)),
),
Expanded(flex: 1,child: IconContainer(Icons.ac_unit,color: Color.fromARGB(255, 9, 31, 155)),
),
],);
}}

(2)

class HomePage2 extends StatelessWidget {
const HomePage2({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Flex(
direction: Axis.vertical, // 垂直
//direction: Axis.horizontal, //水平
children: [
Expanded(flex: 2, child: IconContainer(Icons.home, color: Colors.red)),
Expanded(
flex: 1,
child: IconContainer(Icons.search, color: Colors.orange),
)],
);
}}

10、弹性布局(Flex Expanded)的更多相关文章

  1. 弹性布局flex

    前几天写过怪异盒子布局,以前在项目中用到弹性布局flex这个属性,当时没深入研究,这里各种查阅各种测试,把这个属性记录下 以免忘记, 弹性布局:是提供一种更加有效的方式来对一个容器中的条目进行排列.对 ...

  2. 前端入门5-CSS弹性布局flex

    本篇文章已授权微信公众号 dasu_Android(大苏)独家发布 声明 本系列文章内容全部梳理自以下四个来源: <HTML5权威指南> <JavaScript权威指南> MD ...

  3. Flutter布局----弹性布局 (Flex)

    弹性布局(Flex) 弹性布局允许子组件按照一定比例来分配父容器空间.弹性布局的概念在其它UI系统中也都存在,如H5中的弹性盒子布局,Android中的FlexboxLayout等.Flutter中的 ...

  4. Flutter 布局类组件:弹性布局(Flex)

    前言 弹性布局允许子组件按照一定比例来分配父容器空间,Flutter中的弹性布局主要通过Flex和Expanded来配合实现. Flex Flex组件可以沿着水平或垂直方向排列子组件,如果你知道主轴方 ...

  5. 移动端弹性布局--flex

    目前,Flex布局,可以简便.完整.响应式地实现各种页面布局.而且,它已得到了所有浏览器的支持,这意味着,我们能很安全地使用这项功能. 如果你对弹性网页布局感兴趣,那可别错过flex这么好用的属性哦. ...

  6. 弹性布局-flex

    浅谈display:flex   display:flex 意思是弹性布局 首先flex的出现是为了解决哪些问题呢? 一.页面行排列布局 像此图左右两个div一排显示 可以用浮动的布局方式 html部 ...

  7. 弹性布局Flex的基本语法

    一.Flex的简介 Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性.用六个字概括弹性布局就是简单.方便.快速. flex( fle ...

  8. 弹性布局--flex方向

    flex方向 flex方向由flex-direction特性决定,用于定义弹性布局模式.flex-direction共有4种模式:从左向右.从右向左.从上往下.从下往上. 主轴 主轴的起点与终点定义了 ...

  9. 微信小程序页面布局之弹性布局-Flex介绍

    布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂直居中就不容易实现. 2009年,W3C 提出了一种新 ...

  10. 简单探讨弹性布局flex

    css 弹性布局: 盒子模型: box-sizing属性1.content-box 正常的普通的盒子模型用padding和border会使盒子变大:(向外扩张)2.border-box 盒子模型,pa ...

随机推荐

  1. crontab guru

    https://crontab.guru/every-5-minutes Cron Job Monitoring crontab guru The quick and simple editor fo ...

  2. TopCoder 15903 EllysNim

    TopCoder 15903 EllysNim(https://vjudge.net/problem/TopCoder-15903) \(n\)看似有点东西,实际上就只是一个贪心... 设\(i\)表 ...

  3. osx12.6设置全屏

    首先安装VMWARE TOOLS就是unlocker208下的tool的darwin.iso 然后进入终端命令,这里要说一下,好多资料说按COMMAND键,反正我是没有进去,直接在vmware菜单里选 ...

  4. [ABC207E] Mod i 题解

    Mod i 题目大意 给定一个序列 \(a\),问将其划分成若干段,满足第 \(i\) 段的和是 \(i\) 的倍数的划分方案的个数. 思路分析 考虑 DP,设 \(f_{i,j}\) 表示将序列中前 ...

  5. Spring Cloud Gateway系列:简介和入门

    一.简介 官网:https://cloud.spring.io/spring-cloud-gateway/reference/html/ SpringCloud Gateway是SpringCloud ...

  6. .NET中的数组在内存中如何布局?

    总的来说,.NET的值类型和引用类型都映射一段连续的内存片段.不过对于值类型对象来说,这段内存只需要存储其字段成员,而对应引用类型对象,还需要存储额外的内容.就内存布局来说,引用类型有两个独特的存在, ...

  7. QSplitter 自我总结

    ①.QSplitter(QWidget* parent = Q_NULLPTR); //构造函数 QSplitter(Qt::Orientation orientation , QWidget* pa ...

  8. C++基础杂记(1)

    结构体中的位字段 共用体 烦人的枚举 枚举的声明与赋值 枚举的取值范围与强制类型转换 枚举的注意事项 指针 为什么是 int* ptr 而不是 int *ptr ? 避免危险的指针 使用array和v ...

  9. Go 方法介绍,理解“方法”的本质

    Go 方法介绍,理解"方法"的本质 目录 Go 方法介绍,理解"方法"的本质 一.认识 Go 方法 1.1 基本介绍 1.2 声明 1.2.1 引入 1.2.2 ...

  10. 万字长文:从 C# 入门学会 RabbitMQ 消息队列编程

    RabbitMQ 教程 目录 RabbitMQ 教程 RabbitMQ 简介 安装与配置 安装 RabbitMQ 发布与订阅模型 生产者.消费者.交换器.队列 多工作队列 交换器类型 Direct F ...