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

Flutter

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

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

スポンサーリンク

方法

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

TextFormFieldの横幅の最大値を設定するには、ConstrainedBoxを使います。

まず、TextFormFieldをConstrainedBoxでラップします。

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

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

ConstrainedBox(
  constraints: BoxConstraints(
    maxWidth: /*横幅の最大値*/,
  ),
  child: TextFormField(),
),

これでTextFormFieldの横幅の最大値を設定できます。

使用例

以下は、使用例です。

ConstrainedBox(
  constraints: BoxConstraints(
    maxWidth: 200,
  ),
  child: TextFormField(
    decoration: InputDecoration(
      border: OutlineInputBorder(),
    ),
  ),
),

コメント

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