updateEditingValueWithDeltas method
Requests that this client update its editing state by applying the deltas received from the engine.
The list of TextEditingDelta's are treated as changes that will be applied to the client's editing state. A change is any mutation to the raw text value, or any updates to the selection and/or composing region.
{@tool snippet} This example shows what an implementation of this method could look like.
class MyClient with DeltaTextInputClient {
TextEditingValue? _localValue;
@override
void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) {
if (_localValue == null) {
return;
}
TextEditingValue newValue = _localValue!;
for (final TextEditingDelta delta in textEditingDeltas) {
newValue = delta.apply(newValue);
}
_localValue = newValue;
}
// ...
}
{@end-tool}
Implementation
@override
updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) {
/// Handles IME composition only
for (var d in textEditingDeltas) {
if (d is TextEditingDeltaInsertion) {
// composing text
if (d.composing.isValid) {
_composingText += d.textInserted;
_controller.imeSetComposition(_composingText);
} else if (!Platform.isWindows) {
_controller.imeCommitText(d.textInserted);
}
} else if (d is TextEditingDeltaDeletion) {
if (d.composing.isValid) {
if (_composingText == d.textDeleted) {
_composingText = "";
}
_controller.imeSetComposition(_composingText);
}
} else if (d is TextEditingDeltaReplacement) {
if (d.composing.isValid) {
_composingText = d.replacementText;
_controller.imeSetComposition(_composingText);
}
} else if (d is TextEditingDeltaNonTextUpdate) {
if (_composingText.isNotEmpty) {
_controller.imeCommitText(_composingText);
_composingText = '';
}
}
}
}