跳至主要內容

showAutocorrectionPromptRect 方法已新增至 TextInputClient

摘要

#

一個新的方法 void showAutocorrectionPromptRect(int start, int end) 已新增至 TextInputClient 介面。

背景

#

為了顯示 iOS 的自動校正反白效果,iOS 文字輸入外掛程式需要一種方法來通知 Flutter 框架反白效果的起始和結束位置。

變更說明

#

TextInputClient 介面中新增了一個新的方法 void showAutocorrectionPromptRect(int start, int end)。當 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