LoginSignup
kokogento
@kokogento (ここ げんと)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Flutter TextFormFieldで改行できない

なぜか改行ができない

TextFormFieldでTwitterの投稿画面のように、enterやreturnのようなキーで改行できるようにしたいです。

該当のソース

SliverList(
          delegate: SliverChildListDelegate(<Widget>[
            Container(
              padding: EdgeInsets.symmetric(
                vertical: 3 * SizeConfig.blockSizeVertical,
                horizontal: 3 * SizeConfig.blockSizeVertical,
              ),
              child: Column(
                children: <Widget>[
                 // 省略
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Container(
                        width: double.infinity,
                        child: Text(
                          '作品の見所',
                          style: Theme.of(context).textTheme.headline5,
                          textAlign: TextAlign.left,
                        ),
                      ),
                    ],
                  ),
                  Form(
                    key: _formKey,
                    child: ListView(
                      padding: EdgeInsets.only(top: 10),
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      children: <Widget>[
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Container(
                              width: 50,
                              height: 400,
                              decoration: BoxDecoration(
                                  border: Border.all(
                                    width: 1,
                                    color: Colors.grey,
                                  ),
                                  shape: BoxShape.circle),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text('1'),
                                ],
                              ),
                            ),
                            SpaceBox.width(10),
                            Expanded(
                              child: TextFormField(
                                controller: _point1Controller,
                                keyboardType: TextInputType.multiline,
                                maxLength: null,
                                textInputAction: TextInputAction.newline,
                                decoration: InputDecoration(labelText: '見所1'),
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ]),
        )

なぜForm>ListView>Rowなのかと言うと、見所の入力フィールドを①〜③まで作りたいからです。

スクリーンショット 2021-06-14 0.19.07.jpg

疑問点

keyboardType: TextInputType.multiline,
maxLength: null,
textInputAction: TextInputAction.newline,

TextFormFieldに上記を追加するだけで改行できると思ったのですが、なぜできないのでしょうか?

0

1Answer

keyboardType: TextInputType.multiline,
maxLength: null, // これがミス。。。「Length」ではなく「Lines」!!!
maxLines: null,
textInputAction: TextInputAction.newline,

これで普通に改行できるようになりました。。。:scream:

こんなしょうもないミスで数時間を無駄にしました。。。

0

Your answer might help someone💌