Rai*_*ann 11 textfield autoscroll flutter
我正在实现一个 TextFormField,并将 maxLines 属性设置为 3。一旦用户从他的第四行开始,如何让 TextFormField 向下滚动?目前光标不再可见,直到用户手动向下滚动。有没有办法自动执行此操作?
这种行为实际上在“文本字段”示例中的 flutter_gallery 应用程序中有所体现。只需在“实时故事”输入中输入长文本,直到它到达第四行。
我的代码的重要部分实际上是这样的:
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,
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我还没有找到解决此问题的方法。
此问题会影响 iOS 和 android。
Deb*_*rah 15
我们的团队通过嵌套一些现有的小部件来实现这一点:
// 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
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
我们得到了Darky 的帮助来获得小部件订购和正确的小部件以使其工作。
在最新的 flutter 1.20.4 中,该文本字段在达到最大高度时会滚动。
Container(
constraints: BoxConstraints(maxHeight: 200),
child: TextField(
maxLines: null,
.......
)
)
Run Code Online (Sandbox Code Playgroud)
如果您在 Raw 或列中使用文本字段,请将其包装在Expanded小部件中
您可以使用BoxConstraints和设置maxHeight您的 TextField
Container(
constraints: BoxConstraints(maxHeight: 100),
child: SingleChildScrollView(
child: TextField(
maxLines: null,
),
),
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17460 次 |
| 最近记录: |