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

Flutter

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

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

スポンサーリンク

方法

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

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

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

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ConstrainedBox(
          constraints: BoxConstraints(
            minHeight: 100,//最小の高さ
          ),
          child: Card(
            color: Colors.blue,
            child: Text(
              'こんにちは',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
      ),
    );
  }

コメント

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