我正在实现一个 TextFormField,其 maxLines 属性设置为 3。当用户从第四行开始时,如何使 TextFormField 向下滚动?目前,光标不再可见,直到用户手动向下滚动。有没有办法自动执行此操作?
这种行为实际上在 flutter_gallery 应用程序的“文本字段”示例中有所体现。只需在“Live Story”输入中输入长文本,直到到达第四行。
我的代码的重要部分实际上如下所示:
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,
),
),
);
}
}
到目前为止,我还没有找到解决此问题的方法。
此问题同时影响 iOS 和 Android。
我们的团队通过嵌套一些现有的小部件来实现这一点:
// 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
),
),
);
}
我们得到了帮助Darky https://stackoverflow.com/users/8394265/darky获取小部件排序和正确的小部件以使其正常工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)