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