Unverified Commit daa6b2cc authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

More EditableText docs (#66864)

parent dd41f41f
...@@ -756,7 +756,17 @@ abstract class TextSelectionDelegate { ...@@ -756,7 +756,17 @@ abstract class TextSelectionDelegate {
/// Gets the current text input. /// Gets the current text input.
TextEditingValue get textEditingValue; TextEditingValue get textEditingValue;
/// Sets the current text input (replaces the whole line). /// Indicates that the user has requested the delegate to replace its current
/// text editing state with [value].
///
/// The new [value] is treated as user input and thus may subject to input
/// formatting.
///
/// See also:
///
/// * [EditableTextState.textEditingValue]: an implementation that applies
/// additional pre-processing to the specified [value], before updating the
/// text editing state.
set textEditingValue(TextEditingValue value); set textEditingValue(TextEditingValue value);
/// Hides the text selection toolbar. /// Hides the text selection toolbar.
...@@ -784,6 +794,7 @@ abstract class TextSelectionDelegate { ...@@ -784,6 +794,7 @@ abstract class TextSelectionDelegate {
/// See also: /// See also:
/// ///
/// * [TextInput.attach] /// * [TextInput.attach]
/// * [EditableText], a [TextInputClient] implementation.
abstract class TextInputClient { abstract class TextInputClient {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions. /// const constructors so that they can be used in const expressions.
...@@ -805,6 +816,9 @@ abstract class TextInputClient { ...@@ -805,6 +816,9 @@ abstract class TextInputClient {
AutofillScope? get currentAutofillScope; AutofillScope? get currentAutofillScope;
/// Requests that this client update its editing state to the given value. /// Requests that this client update its editing state to the given value.
///
/// The new [value] is treated as user input and thus may subject to input
/// formatting.
void updateEditingValue(TextEditingValue value); void updateEditingValue(TextEditingValue value);
/// Requests that this client perform the given action. /// Requests that this client perform the given action.
...@@ -832,7 +846,10 @@ abstract class TextInputClient { ...@@ -832,7 +846,10 @@ abstract class TextInputClient {
/// ///
/// See also: /// See also:
/// ///
/// * [TextInput.attach] /// * [TextInput.attach], a method used to establish a [TextInputConnection]
/// between the system's text input and a [TextInputClient].
/// * [EditableText], a [TextInputClient] that connects to and interacts with
/// the system's text input using a [TextInputConnection].
class TextInputConnection { class TextInputConnection {
TextInputConnection._(this._client) TextInputConnection._(this._client)
: assert(_client != null), : assert(_client != null),
...@@ -889,7 +906,8 @@ class TextInputConnection { ...@@ -889,7 +906,8 @@ class TextInputConnection {
TextInput._instance._updateConfig(configuration); TextInput._instance._updateConfig(configuration);
} }
/// Requests that the text input control change its internal state to match the given state. /// Requests that the text input control change its internal state to match
/// the given state.
void setEditingState(TextEditingValue value) { void setEditingState(TextEditingValue value) {
assert(attached); assert(attached);
TextInput._instance._setEditingState(value); TextInput._instance._setEditingState(value);
...@@ -1042,9 +1060,57 @@ RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map<String, d ...@@ -1042,9 +1060,57 @@ RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map<String, d
/// An low-level interface to the system's text input control. /// An low-level interface to the system's text input control.
/// ///
/// To start interacting with the system's text input control, call [attach] to
/// establish a [TextInputConnection] between the system's text input control
/// and a [TextInputClient]. The majority of commands available for
/// interacting with the text input control reside in the returned
/// [TextInputConnection]. The communication between the system text input and
/// the [TextInputClient] is asynchronous.
///
/// The platform text input plugin (which represents the system's text input)
/// and the [TextInputClient] usually maintain their own text editing states
/// ([TextEditingValue]) separately. They must be kept in sync as long as the
/// [TextInputClient] is connected. The following methods can be used to send
/// [TextEditingValue] to update the other party, when either party's text
/// editing states change:
///
/// * The [TextInput.attach] method allows a [TextInputClient] to establish a
/// connection to the text input. An optional field in its `configuration`
/// parameter can be used to specify an initial value for the platform text
/// input plugin's [TextEditingValue].
///
/// * The [TextInputClient] sends its [TextEditingValue] to the platform text
/// input plugin using [TextInputConnection.setEditingState].
///
/// * The platform text input plugin sends its [TextEditingValue] to the
/// connected [TextInputClient] via a "TextInput.setEditingState" message.
///
/// * When autofill happens on a disconnected [TextInputClient], the platform
/// text input plugin sends the [TextEditingValue] to the connected
/// [TextInputClient]'s [AutofillScope], and the [AutofillScope] will further
/// relay the value to the correct [TextInputClient].
///
/// When synchronizing the [TextEditingValue]s, the communication may get stuck
/// in an infinite when both parties are trying to send their own update. To
/// mitigate the problem, only [TextInputClient]s are allowed to alter the
/// received [TextEditingValue]s while platform text input plugins are to accept
/// the received [TextEditingValue]s unmodified. More specifically:
///
/// * When a [TextInputClient] receives a new [TextEditingValue] from the
/// platform text input plugin, it's allowed to modify the value (for example,
/// apply [TextInputFormatter]s). If it decides to do so, it must send the
/// updated [TextEditingValue] back to the platform text input plugin to keep
/// the [TextEditingValue]s in sync.
///
/// * When the platform text input plugin receives a new value from the
/// connected [TextInputClient], it must accept the new value as-is, to avoid
/// sending back an updated value.
///
/// See also: /// See also:
/// ///
/// * [TextField], a widget in which the user may enter text. /// * [TextField], a widget in which the user may enter text.
/// * [EditableText], a [TextInputClient] that connects to [TextInput] when it
/// wants to take user input from the keyboard.
class TextInput { class TextInput {
TextInput._() { TextInput._() {
_channel = SystemChannels.textInput; _channel = SystemChannels.textInput;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment