11

maxLines 属性を 3 に設定して TextFormField を実装しています。ユーザーが 4 行目から始めたら、TextFormField を下にスクロールするにはどうすればよいですか? 現時点では、ユーザーが手で下にスクロールするまで、カーソルは表示されません。これを自動的に行う方法はありますか?

この動作は、実際には flutter_gallery アプリの「テキスト フィールド」の例で取り上げられています。4 行目まで、「ライブ ストーリー」入力に長いテキストを入力するだけです。
私のコードの重要な部分は、実際には次のようになります。

import 'package:flutter/material.dart';

class TextFormFieldDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Form(
        child: new TextFormField(
          maxLines: 3,
        ),
      ),
    );
  }
}

これまでのところ、この問題の回避策は見つかりませんでした。
この問題は、iOS と Android の両方に影響します。

4

7 に答える 7

15

私たちのチームは、いくつかの既存のウィジェットをネストすることでこれを実現しました。

// create the illusion of a beautifully scrolling text box
return new Container(
    color: Colors.gray,
  padding: new EdgeInsets.all(7.0),

  child: new ConstrainedBox(
    constraints: new BoxConstraints(
      minWidth: _contextWidth(),
      maxWidth: _contextWidth(),
      minHeight: AppMeasurements.isLandscapePhone(context) ? 25.0 : 25.0,
      maxHeight: 55.0,
    ),

    child: new SingleChildScrollView(
      scrollDirection: Axis.vertical,
      reverse: true,

        // here's the actual text box
        child: new TextField(
          keyboardType: TextInputType.multiline,
          maxLines: null, //grow automatically
          focusNode: mrFocus,
          controller: _textController,
          onSubmitted: currentIsComposing ? _handleSubmitted : null,
          decoration: new InputDecoration.collapsed(
            hintText: ''Please enter a lot of text',
          ),
        ),
        // ends the actual text box

      ),
    ),
  );
}

ウィジェットの順序付けと、それを機能させるための正しいウィジェットを取得するために、 Darkyの助けを借りました。

于 2018-02-09T18:37:05.067 に答える