[Flutter]Cardに最大の高さを設定するには?

Flutter

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

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

スポンサーリンク

方法

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

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

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

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

そして、BoxConstraintsの引数「maxHeight」に最大の高さを設定します。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ConstrainedBox(
          constraints: BoxConstraints(
            maxHeight: 50, //最大の高さ
          ),
          child: Card(
            child: Container(
              height: 300,
              width: 100,
              child: Text('Flutter'),
              color: Colors.yellow,
            ),
          ),
        ),
      ),
    );
  }

コメント

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