当前位置:网站首页>flutter系列之:UI layout简介
flutter系列之:UI layout简介
2022-06-10 17:43:00 【InfoQ】
简介
flutter中layout的分类
- Align -- 用来对其包含在其中的组件进行对其操作。
- AspectRatio -- 对其中的组件进行比例缩放。
- Baseline -- 通过使用子组件的baseline来进行定位。
- Center -- 自组件位于中间。
- ConstrainedBox -- 类似于IOS中的constrain,表示子组件的限制条件。
- Container -- 一个常用的widget,可以用来包含多个其他的widget。
- CustomSingleChildLayout -- 将其单个子项的布局推迟。
- Expanded -- 将Row, Column 或者 Flex的child进行扩展。
- FittedBox -- 根据fit来缩放和定位其child。
- FractionallySizedBox -- 将child按照总可用空间进行调整。
- IntrinsicHeight -- 一个将其child调整为child固有高度的小部件。
- IntrinsicWidth -- 一个将其child调整为child固有宽度的小部件。
- LimitedBox -- 限制一个box的size。
- Offstage -- 将child放入render tree中,但是却并不触发任何重绘。
- OverflowBox -- 允许child覆盖父组件的限制。
- Padding -- 为child提供padding。
- SizedBox -- 给定size的box。
- SizedOverflowBox -- 可以覆盖父组件限制的box。
- Transform -- 子组件可以变换。
- Column -- 表示一列child。
- CustomMultiChildLayout -- 使用代理来定位和缩放子组件。
- Flow -- 流式布局。
- GridView -- 网格布局。
- IndexedStack -- 从一系列的child中展示其中的一个child。
- LayoutBuilder -- 可以依赖父组件大小的widget tree。
- ListBody -- 根据给定的axis来布局child。
- ListView -- 可滚动的列表。
- Row -- 表示一行child。
- Stack -- 栈式布局的组件。
- Table -- 表格形式的组件。
- Wrap -- 可以对子child进行动态调整的widget。
- CupertinoSliverNavigationBar -- 是一种IOS风格的导航bar。
- CustomScrollView -- 可以自定义scroll效果的ScrollView。
- SliverAppBar -- material风格的app bar,其中包含了CustomScrollView。
- SliverChildBuilderDelegate -- 使用builder callback为slivers提供child的委托。
- SliverChildListDelegate -- 使用list来为livers提供child的委托。
- SliverFixedExtentList -- 固定axis extent的sliver。
- SliverGrid -- child是二维分布的sliver。
- SliverList -- child是线性布局的sliver。
- SliverPadding -- 提供padding的sliver。
- SliverPersistentHeader -- 可变size的sliver。
- SliverToBoxAdapter -- 包含单个box widget的Sliver。
常用layout举例
class Row extends Flex {
Row({
Key? key,
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
MainAxisSize mainAxisSize = MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
TextDirection? textDirection,
VerticalDirection verticalDirection = VerticalDirection.down,
TextBaseline? textBaseline, // NO DEFAULT: we don't know what the text's baseline should be
List<Widget> children = const <Widget>[],
}) : super(
children: children,
key: key,
direction: Axis.horizontal,
mainAxisAlignment: mainAxisAlignment,
mainAxisSize: mainAxisSize,
crossAxisAlignment: crossAxisAlignment,
textDirection: textDirection,
verticalDirection: verticalDirection,
textBaseline: textBaseline,
);
}
class Column extends Flex {
Column({
Key? key,
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
MainAxisSize mainAxisSize = MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
TextDirection? textDirection,
VerticalDirection verticalDirection = VerticalDirection.down,
TextBaseline? textBaseline,
List<Widget> children = const <Widget>[],
}) : super(
children: children,
key: key,
direction: Axis.vertical,
mainAxisAlignment: mainAxisAlignment,
mainAxisSize: mainAxisSize,
crossAxisAlignment: crossAxisAlignment,
textDirection: textDirection,
verticalDirection: verticalDirection,
textBaseline: textBaseline,
);
}
class RowWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
textDirection: TextDirection.ltr,
children: [
YellowBox(),
YellowBox(),
YellowBox(),
],
);
}
}
class YellowBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.yellow,
border: Border.all(),
),
);
}
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: RowWidget()
);
}

mainAxisAlignment: MainAxisAlignment.spaceEvenly

return Row(
textDirection: TextDirection.ltr,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
YellowBox(),
YellowBox(),
Expanded(
child: YellowBox(),
)
],
);

const Expanded({
Key? key,
int flex = 1,
required Widget child,
}) : super(key: key, flex: flex, fit: FlexFit.tight, child: child);
children: [
YellowBox(),
YellowBox(),
Expanded(
flex:2,
child: YellowBox(),
)
],
children: [
Expanded(
child: YellowBox(),
),
Expanded(
child: YellowBox(),
),
Expanded(
flex: 2,
child: YellowBox(),
)
],

children: [
Expanded(
child: YellowBox(),
),
SizedBox(
width: 100,
),
Expanded(
child: YellowBox(),
),
Expanded(
flex: 2,
child: YellowBox(),
)
],

children: [
Expanded(
child: YellowBox(),
),
Spacer(flex: 2),
Expanded(
child: YellowBox(),
),
Expanded(
flex: 2,
child: YellowBox(),
)
],

总结
边栏推荐
- c语言---4 初识常量
- AOE network critical path
- XML&Xpath解析
- 我在做一件很酷的事情
- 自定义类型:结构体
- QtMqtt 源码编译设置KeepAlive后ping包超时错误不返回问题修复(QMQTT::MqttNoPingResponse,QMQTT::ClientPrivate::onPingTimeo)
- Abbexa CDAN1 siRNA使用说明书
- [technical analysis] discuss the production process and technology of big world games - preliminary process
- Numpy - record
- 小程序积分商城如何实现营销目的
猜你喜欢

线性移动棋

PCA principal component analysis tutorial (origin analysis & drawing, without R language)

pwnable start

c语言---11 分支语句if else

yml文件配置参数定义字典和列表

C language -- 13 loop statement while

AOV network topology sorting

c语言---4 初识常量

Detailed explanation of MySQL windowing function

QtMqtt 源码编译设置KeepAlive后ping包超时错误不返回问题修复(QMQTT::MqttNoPingResponse,QMQTT::ClientPrivate::onPingTimeo)
随机推荐
ZigBee模块无线传输星形拓扑组网结构简介
阅读micropyton源码-添加C扩展类模块(3)
Classic topics of leetcode tree (I)
IP summary (tcp/ip volumes 1 and 2)
Unity stepping on the pit record: if you inherit monobehavior, the constructor of the class may be called multiple times by unity. Do not initialize the constructor
将同一文件夹下的大量文件根据设定分至多组
改变世界的开发者丨玩转“俄罗斯方块”的瑶光少年
Analysis of transfer Refund Scheme in e-commerce industry
Abbexa 细菌基因组 DNA 试剂盒介绍
Record of cmake and GCC installation
Step on the pit. The BigDecimal was improperly used, resulting in P0 accident!
LeetCode 255. Verifying preorder traversal sequence binary search tree*
Noise line h5js effect realized by canvas
正斜杠“/”、反斜杠“\、”转义字符“\”、文件路径分割符傻傻记不清楚
Summary of all contents of cloud computing setup to ensure that a complete cloud computing server can be built, including node installation, instance allocation, network configuration, etc
XML & XPath parsing
Abbexa AML1 DNA 结合 ELISA 试剂盒说明书
High number_ Chapter 6 infinite series__ Properties of positive series
js模糊阴影跟随动画js特效插件
一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue