Wil*_*ian 6 flutter flutter-layout
如上所示,当从可滚动SelectableText小部件中选择文本时,它最初会自动滚动到顶部。预期的行为是当选择文本时滚动保留在底部。
我已经尝试了 stackoverflow 上的所有答案,但似乎这是颤振错误,但如果有人现在有解决方法,那就太好了!
您可以在此github 存储库中找到代码。
我找到了一个简短的丑陋的解决方法。
似乎可选文本试图通过跳转到其文本字段来确保看到光标/所选文本。在这种情况下,当文本字段太大时,它会跳转到开头。
由于在我的应用程序中,我只有较长的可选文本,无需在较短的文本字段中对其进行编辑,因此我只是注释了选择文本时调用跳转的行。
在文件中:flutter/packages/flutter/lib/src/widgets/editable_text.dart
在功能上:userUpdateTextEditingValue
注释掉调用以下内容的行:_scheduleShowCaretOnScreen
像这样:
@override
void userUpdateTextEditingValue(TextEditingValue value, SelectionChangedCause? cause) {
// Compare the current TextEditingValue with the pre-format new
// TextEditingValue value, in case the formatter would reject the change.
final bool shouldShowCaret = widget.readOnly
? _value.selection != value.selection
: _value != value;
if (shouldShowCaret) {
// _scheduleShowCaretOnScreen(); --> This line causes the problem
}
_formatAndSetValue(value, cause, userInteraction: true);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1618 次 |
| 最近记录: |