Método showAutocorrectionPromptRect agregado a TextInputClient
Se agregó un nuevo método, void showAutocorrectionPromptRect(int start, int end), a la interfaz TextInputClient
Resumen
#Se agregó un nuevo método, void showAutocorrectionPromptRect(int start, int end),
a la interfaz TextInputClient.
Contexto
#Para mostrar el resaltado de autocorrección de iOS, el plugin de entrada de texto de iOS necesitaba una forma de informar al framework de Flutter la posición de inicio y fin del resaltado.
Descripción del cambio
#Un nuevo método, void showAutocorrectionPromptRect(int start, int end),
fue agregado a la interfaz TextInputClient. iOS llama a este método
cuando encuentra un nuevo candidato potencial de autocorrección
en la entrada del usuario actual, o cuando cambia el rango de un candidato
resaltado previamente.
Guía de migración
#Si tu aplicación no implementa ni hereda de TextInputClient,
no se necesita ninguna migración. Si tu aplicación no está dirigida a iOS,
o la clase que implementó la interfaz textInputClient no
admite autocorrección, solo necesitas agregar una implementación vacía
para el nuevo método:
class CustomTextInputClient implements TextInputClient {
void showAutocorrectionPromptRect(int start, int end) {}
}
De lo contrario, si tu aplicación está dirigida a iOS y admite autocorrección en iOS,
te recomendamos que agregues una implementación adecuada de
void showAutocorrectionPromptRect(int start, int end)
a tu subclase de TextInputClient.
Código después de la migración:
// 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);
});
}
}
Timeline
#En la versión estable: 1.20
Referencias
#Documentación de la API:
Problema relevante:
PR relevante:
A menos que se indique lo contrario, la documentación de este sitio refleja Flutter 3.44.0. Página actualizada por última vez el 2026-05-05. Ver código fuente oreportar un problema.