通过拖动来调整TextField的大小

时间:2019-09-02 16:37:03

标签: flutter flutter-layout

有什么方法可以创建类似于这些点的内容,从而有助于扩展$oneToThirtyDue = Amortization::distinct('amortizations.loan_id') ->join('loans', 'loans.id', '=', 'amortizations.loan_id') ->select('loans.loan_type',\DB::raw('SUM(loans.loan_balance) as total_val')) ->where('amortizations.payment_status',0) ->where('amortizations.schedule', '<', date('Y-m-d')) ->where('amortizations.past_due', '<=', 30) ->groupBy('loans.loan_type') ->orderBy('loans.loan_type') ->get();

enter image description here

1 个答案:

答案 0 :(得分:6)

截屏:

enter image description here

创建一个小部件。

class ExpandableTextField extends StatefulWidget {
  final double height;
  final double maxHeight;
  final double dividerHeight;
  final double dividerSpace;
  final Widget child;

  const ExpandableTextField({
    Key key,
    @required this.child,
    this.height = 44,
    this.maxHeight = 300,
    this.dividerHeight = 40,
    this.dividerSpace = 2,
  }) : super(key: key);

  @override
  _ExpandableTextFieldState createState() => _ExpandableTextFieldState();
}

class _ExpandableTextFieldState extends State<ExpandableTextField> {
  double _height, _maxHeight, _dividerHeight, _dividerSpace;

  @override
  void initState() {
    super.initState();
    _height = widget.height;
    _maxHeight = widget.maxHeight;
    _dividerHeight = widget.dividerHeight;
    _dividerSpace = widget.dividerSpace;
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: _maxHeight,
      child: Column(
        children: <Widget>[
          SizedBox(
            height: _height,
            child: widget.child,
          ),
          SizedBox(height: _dividerSpace),
          Container(
            height: _dividerHeight,
            width: 60,
            child: GestureDetector(
              child: FittedBox(child: Text("----")),
              onPanUpdate: (details) {
                setState(() {
                  _height += details.delta.dy;

                  // prevent overflow if height is more/less than available space
                  var maxLimit = _maxHeight - _dividerHeight - _dividerSpace;
                  var minLimit = 44.0;

                  if (_height > maxLimit)
                    _height = maxLimit;
                  else if (_height < minLimit) 
                    _height = minLimit;
                });
              },
            ),
          )
        ],
      ),
    );
  }
}

使用方式:

ExpandableTextField(
  child: TextField(
    decoration: InputDecoration(hintText: "Enter a message"),
    maxLines: 100, // give any number, but make sure it is not small
  ),
)