[Flutter]Cardに最大の横幅を設定するには?

Flutter

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

Cardに最大の横幅を設定する方法を紹介します。

スポンサーリンク

方法

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

Cardに最大の横幅を設定するには、BoxConstraintsを使います。

まず、CardをBoxContrainstsのchildに指定します。

次に、BoxConstraintsの引数「constraints」にBoxConstraintsを指定します。

そして、BoxConstraintsの引数「maxWidth」に最大の横幅を設定します。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ConstrainedBox(
          constraints: BoxConstraints(
            maxWidth: 200, //最大の横幅
          ),
          child: Card(
            child: Container(
              height: 200,
              width: 1000,
              child: Text('Flutter'),
              color: Colors.yellow,
              alignment: Alignment.center,
            ),
          ),
        ),
      ),
    );
  }

コメント

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