Flutter expand TextField using dragging and button click. Use the below example to expand TextField using dragging and button click in your flutter app.
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | class YourPage extends StatefulWidget { @override _YourPageState createState() => _YourPageState(); } class _YourPageState extends State<YourPage> { double _maxHeight = 200, _minHeight = 44, _height = 44, _dividerHeight = 56, _offset = 19; int _maxLines = 1; static final Duration _fixDuration = Duration(milliseconds: 500); Duration _duration = _fixDuration; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Padding( padding: const EdgeInsets.all(20), child: SizedBox( height: _maxHeight, child: Column( children: <Widget>[ AnimatedContainer( duration: _duration, height: _height, child: TextField( decoration: InputDecoration(hintText: "Enter a message"), maxLines: _maxLines, ), ), Container( height: _dividerHeight, width: 200, child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[ IconButton( icon: Icon(Icons.arrow_downward), onPressed: () { if (_height <= _maxHeight - _offset - _dividerHeight) { setState(() { _duration = _fixDuration; _height += _offset; _maxLines++; }); } }, ), GestureDetector( child: Icon(Icons.drag_handle), onPanUpdate: (details) { setState(() { _height += details.delta.dy; _duration = Duration.zero; // prevent overflow if height is more/less than available space var maxLimit = _maxHeight - _dividerHeight; var minLimit = 44.0; if (_height > maxLimit) _height = maxLimit; else if (_height < minLimit) _height = minLimit; _maxLines = 100; }); }, ), IconButton( icon: Icon(Icons.arrow_upward), onPressed: () { if (_height >= _minHeight + _offset) { setState(() { _duration = _fixDuration; _height -= _offset; }); } }, ), ], ), ) ], ), ), ), ); } } |
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.