[Flutter]Rowの背景色を設定するには?

Flutter

どうも、ちょげ(@chogetarou)です。

Rowの背景色を設定する方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

Rowの背景色を設定するには、Containerを使います。

まず、RowをContainerでラップします。

そして、Containerの引数「color」に背景色を指定します。

Container(
  color: /*背景色*/,
  child: Row(
    children: [
      ・・・
    ],
  ),
),

これでRowの背景色を設定することが出来ます。

使用例

以下は、使用例です。

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Center(
          child: Container(
            color: Colors.blue,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                for (var i = 0; i < 10; i++)
                  Text(
                    '$i',
                    style: TextStyle(color: Colors.white),
                  )
              ],
            ),
            height: 200,
          ),
        ),
      ),
    );
  }

コメント

タイトルとURLをコピーしました