Automatically scroll multiline TextFormField when it extends the maxLines attribute. Our team accomplished this by nesting some existing widgets:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // 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 ), ), ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.