TextInputClient 方法 showAutocorrectionPromptRect 已添加
概述
#一个新的方法 void showAutocorrectionPromptRect(int start, int end)
已添加到 TextInputClient
接口。
背景
#为了显示 iOS 自动更正高亮,iOS 文本输入插件需要一种方法来将高亮开始和结束位置告知 Flutter 框架。
变更说明
#一个新的方法 void showAutocorrectionPromptRect(int start, int end)
已添加到 TextInputClient
接口。当 iOS 文本输入插件在当前用户输入中找到新的潜在自动更正候选词时,或者当先前高亮候选词的范围发生变化时,iOS 会调用此方法。
迁移指南
#如果您的应用程序不实现或不继承 TextInputClient
,则无需迁移。如果您的应用程序不以 iOS 为目标平台,或者实现了 textInputClient
接口的类不支持自动更正,您只需要为新方法添加一个空实现。
dart
class CustomTextInputClient implements TextInputClient {
void showAutocorrectionPromptRect(int start, int end) {}
}
否则,如果您的应用以 iOS 为目标平台并支持 iOS 上的自动更正,我们建议您在 TextInputClient
子类中添加 void showAutocorrectionPromptRect(int start, int end)
的合理实现。
迁移后的代码
dart
// Assume your `TextInputClient` is a `State` subclass, and it has a variable
// `_currentPromptRectRange` that controls the autocorrection highlight.
class CustomTextInputClient extends State<...> implements TextInputClient {
@override
void updateEditingValue(TextEditingValue value) {
// When the text changes, the highlight needs to be dismissed.
if (value.text != _value.text) {
setState(() {
_currentPromptRectRange = null;
});
}
}
void _handleFocusChanged() {
// When this text input loses focus, the autocorrection highlight needs
// to be dismissed.
if (!_hasFocus) {
setState(() {
_currentPromptRectRange = null;
});
}
}
@override
void showAutocorrectionPromptRect(int start, int end) {
// Updates the range of the highlight, as iOS requested.
// This method isn't called when iOS decides to
// dismiss the highlight.
setState(() {
_currentPromptRectRange = TextRange(start: start, end: end);
});
}
}
时间线
#稳定版本中:1.20
参考资料
#API 文档
相关议题
相关 PR