flutter

Flutter 布局用法总结

2021-08-22  本文已影响0人  Coralline_xss

本篇主要整理 flutter 中多组件布局用法。

一、线性布局:Row、Column

1. 定义

2. 使用说明

Row 为例说明,Column 先省略。

Row(
    children: [
        Container(
          color: Colors.lightGreen,
          child: Row(
            children: [
              Expanded(
                child: Container(
                  color: Colors.red,
                  child: Row(
                    children: [
                      Text("hello world. "),
                      Text("I am Jack "),
                    ],
                  ),
                )
              ),
            ],
          ),
        )
    ]
),

二、弹性布局:Flex

1. 定义

A widget that displays its children in a one-dimensional array. 

flutter 中的弹性布局,主要使用 FlexExpanded 配合实现。

2. 特性

3. 布局算法

4. 相关组件

5. 用法总结

6. Expanded 与 Flexible

(1) Expanded
(2) Flexible

7. 用法示例

Flex(
          axis: Axis.horizontal,
          children: [
            Expanded(
              flex: 1,
              child: Container(
                height: 30.0,
                color: Colors.red,
              ),
            ),
            Spacer(
              flex: 1,
            ),
            Expanded(
              flex: 2,
              child: Container(
                height: 30.0,
                color: Colors.green,
              ),
            ),
          ],
        )

三、流式布局:Wrap、Flow

1. 定义

2. 用法

四、层叠布局:Stack

五、对齐布局:Align、Center

六、布局组件类图

布局组件类图

参考资料:

上一篇 下一篇

猜你喜欢

热点阅读