gpt4 book ai didi

textfield - 扩展 maxLines 属性时自动滚动多行 TextFormField

转载 作者:IT老高 更新时间:2023-10-28 12:45:31 29 4
gpt4 key购买 nike

我正在实现一个将 maxLines 属性设置为 3 的 TextFormField。一旦用户从第四行开始,如何使 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,
),
),
);
}
}

到目前为止,我还没有找到解决此问题的方法。
此问题同时影响 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 的帮助获取小部件排序和正确的小部件以使其工作。

关于textfield - 扩展 maxLines 属性时自动滚动多行 TextFormField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43348254/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com