栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flutter使用拖动和按钮单击来展开TextField

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter使用拖动和按钮单击来展开TextField

Full pre:

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;    });  }},         ),       ],     ),   ) ],          ),        ),      ),    );  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/404279.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号