Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter expand TextField using dragging and button click

enter image description here

How can I increase/decrease the number of maxLines in TextField with dragging and clicking button?

like image 750
DolDurma Avatar asked Sep 09 '19 06:09

DolDurma


People also ask

How to make read more or expand text widget in flutter?

Flutter - Text widget with read more or expand feature. In the mobile applications, sometimes we have to create an item that shows only two or three lines of the complete paragraph. To create such kind of view, we have a to add a button that displays complete content. When the user clicks on that button.

How do I change the value of a text field in flutter?

Flutter TextField and Button Events using Controller - YOC. Manage textField value with controller with onpress ontap click event to change, send or set value of a text field to another with button in Flutter. Press "Enter" to skip to content.

How to make a draggable and expandable Floating Action Button in flutter?

See the example below to make a draggable and expandable floating action button in the Flutter app. First, add floatingpanel Futter package in your dependency by adding the following lines in pubspec.yaml file. This code will generate a movable Floating action button, when you click on button, it will expand with its menu buttons.

How to show large sentences or paragraphs in flutter?

The read more or expandable feature in a Text and other widgets will help you to show large sentences or paragraphs. It shows complete paragraphs when a user clicks on read more button. We can display these feature at the end of sentences, as you can see below. The Flutter framework provides a Text widget to display content.


Video Answer


1 Answers

Screenshot:

enter image description here


Full code:

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;
                          });
                        }
                      },
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
like image 187
CopsOnRoad Avatar answered Oct 18 '22 21:10

CopsOnRoad