1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

FlutterでBottom overflowedが出た場合の対処法

Last updated at Posted at 2021-05-28

長いテキストをTextやTextFormFieldに表示しようとすると"A RenderFlex overflowed by xx pixels on the bottom."というエラーメッセージと共に以下のような画面表示になることがあります。

image.png

解決法(Text)

Textの場合は以下のようにExpandedを使います。

Expanded(child: Text(message))

解決法(TextFormField)

TextFormFieldはmaxLines:を指定するとフォーム内でHTMLのtextarea的に使える複数行入力できるフィールドが作れるのですが、これだと大量のテキストを入力した場合にやはりOverflowの問題が出てしまいます。これを回避するために以下のようにFlexibleとContainerで囲みます。

Flexible(
  child: Container(
    constraints:
        BoxConstraints(minHeight: 200, minWidth: double.infinity),
    child: TextFormField(
      maxLines: 10, // フィールドの高さ
      keyboardType: TextInputType.multiline,
      decoration: InputDecoration(labelText: 'メッセージ'),
    ),
  ),
),

以下のようにOverflowしなくなりました。

image.png

解決法(TextFormField その2)

いくつもオブジェクトがあるFormの中にmultilineのTextFormFieldを入れた場合にOverflowを起こすことがあるのを発見しました。この場合は以下のような感じでListViewでFormを包むようにするとうまくいきました。(参考:[Flutter]スクロール可能なFormFieldの取り扱い)

body: ListView(children: <Widget>[
          Form(
            key: _formKey,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
              // 色々オブジェクト...
              TextFormField(
                  keyboardType: TextInputType.multiline,
                  maxLines: 10,
                  decoration: InputDecoration(
                    labelText: "メッセージ",
                  ),
                ),
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?