当前位置:网站首页>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(),
)
],

总结
边栏推荐
- 待办事项桌面插件,办公族的桌面好帮手
- 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
- JS blur shadow follow animation JS special effect plug-in
- Library for adding progress bar during training --tqdm
- [technical analysis] discuss the production process and technology of big world games - preliminary process
- Summary of vim common commands
- High number_ Chapter 6 infinite series__ Properties of positive series
- AOV网拓扑排序
- LeetCode 321. 拼接最大数***
- JS special effect of canvas divergent particle H5 animation
猜你喜欢
随机推荐
聊聊远程办公那些事儿,参与征文领稿费拿大奖!
Numpy - record
Solve the problem that vs2022 slowly loads a pile of symbols when debugging the program
afl-fuzz多线程
优惠券的工厂与策略模式实现方案
【技术分析】探讨大世界游戏的制作流程及技术——前期流程篇
C language -- 13 loop statement while
Developers changing the world - Yao Guang teenagers playing Tetris
盛最多水得容器
c语言---13 循环语句while
基于业务沉淀组件 =&gt; manage-table
如何定位游戏发热问题
PCA principal component analysis tutorial (origin analysis & drawing, without R language)
Abbexa丙烯酰胺-PEG-NHS说明书
if else的使用太简单?(看懂这篇你的逻辑会进一步提升)
The development of flutter in digital life and the landing practice of Tianyi cloud disk
c语言---3 初识变量
搭建在线帮助中心,轻松帮助客户解决问题
Set up an online help center to easily help customers solve problems
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









