Flutter-最簡單的 Padding 使用範例

背景知識

有使用到 Container 可參考Flutter-最簡單的 Container 使用範例

官方說明頁面

本文 source code

介紹內容

Flutter 使用 Padding 指定 widget 外部向內對齊的大小,簡單示範如下,並進一步測試 EdgeInsets 常用方法

使用方法

使用 Padding 包裹一個紅色 Container

Padding(
        padding: EdgeInsets.fromLTRB(24, 32, 24, 32),
        child: Container(
          padding: const EdgeInsets.all(0.0),
          color: Colors.red,
        ));

上方 EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom)

分別指定左、上、右、下之間隔,效果如下圖

EdgeInsets 常見用法如下

四邊間距相等: const EdgeInsets.all(8.0)

上下相等:padding: const EdgeInsets.symmetric(vertical: 8.0),

只有左邊 padding: const EdgeInsets.only(left: 40.0)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *