Estoy implementando un TextFormField con el atributo maxLines establecido en 3. ¿Cómo puedo hacer que TextFormField se desplace hacia abajo una vez que el usuario comienza con su cuarta línea? Por el momento, el cursor ya no está visible hasta que el usuario se desplaza hacia abajo con la mano. ¿Hay alguna manera de hacer esto automáticamente?
Este comportamiento en realidad se presenta en la aplicación flutter_gallery en el ejemplo de 'Campos de texto'. Simplemente escriba un texto largo en la entrada 'Historia en vivo' hasta que llegue a la cuarta línea.
Las partes importantes de mi código en realidad se ven así:
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, ), ), ); } } Hasta ahora no he encontrado ninguna solución para este problema.
Este problema afecta tanto a iOS como a Android.
Nuestro equipo logró esto anidando algunos widgets existentes:
// 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 ), ), ); }Obtuvimos la ayuda de Darky para obtener el pedido de widgets y los widgets correctos para que funcione.
Esta parece ser una característica que falta en Flutter Framework, he presentado un error para resolverlo: https://github.com/flutter/flutter/issues/9365
Puede usar BoxConstraints y establecer maxHeight de su TextField
Container( constraints: BoxConstraints(maxHeight: 100), child: SingleChildScrollView( child: TextField( maxLines: null, ), ), );