Rationalize text input widgets (#9119)
After this patch, there are three major text input widgets: * EditableText. This widget is a low-level editing control that interacts with the IME and displays a blinking cursor. * TextField. This widget is a Material Design text field, with all the bells and whistles. It is highly configurable and can be reduced down to a fairly simple control by setting its `decoration` property to null. * TextFormField. This widget is a FormField that wraps a TextField. This patch also replaces the InputValue data model for these widgets with a Listenable TextEditingController, which is much more flexible. Fixes #7031
This commit is contained in:
@@ -321,7 +321,7 @@ class FlutterDriver {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Sets the text value of the `Input` widget located by [finder].
|
||||
/// Sets the text value of the [TextField] widget located by [finder].
|
||||
///
|
||||
/// This command invokes the `onChanged` handler of the `Input` widget with
|
||||
/// the provided [text].
|
||||
@@ -330,10 +330,10 @@ class FlutterDriver {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Submits the current text value of the `Input` widget located by [finder].
|
||||
/// Submits the current text value of the [TextField] widget located by [finder].
|
||||
///
|
||||
/// This command invokes the `onSubmitted` handler of the `Input` widget and
|
||||
/// the returns the submitted text value.
|
||||
/// This command invokes the `onSubmitted` handler of the [TextField] widget
|
||||
/// and the returns the submitted text value.
|
||||
Future<String> submitInputText(SerializableFinder finder, {Duration timeout}) async {
|
||||
final Map<String, dynamic> json = await _sendCommand(new SubmitInputText(finder, timeout: timeout));
|
||||
return json['text'];
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart' show RendererBinding;
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -262,20 +263,29 @@ class FlutterDriverExtension {
|
||||
return new ScrollResult();
|
||||
}
|
||||
|
||||
Finder _findEditableText(SerializableFinder finder) {
|
||||
return find.descendant(of: _createFinder(finder), matching: find.byType(EditableText));
|
||||
}
|
||||
|
||||
EditableTextState _getEditableTextState(Finder finder) {
|
||||
final StatefulElement element = finder.evaluate().single;
|
||||
return element.state;
|
||||
}
|
||||
|
||||
Future<SetInputTextResult> _setInputText(Command command) async {
|
||||
final SetInputText setInputTextCommand = command;
|
||||
final Finder target = await _waitForElement(_createFinder(setInputTextCommand.finder));
|
||||
final Input input = target.evaluate().single.widget;
|
||||
input.onChanged(new InputValue(text: setInputTextCommand.text));
|
||||
final Finder target = await _waitForElement(_findEditableText(setInputTextCommand.finder));
|
||||
final EditableTextState editable = _getEditableTextState(target);
|
||||
editable.updateEditingValue(new TextEditingValue(text: setInputTextCommand.text));
|
||||
return new SetInputTextResult();
|
||||
}
|
||||
|
||||
Future<SubmitInputTextResult> _submitInputText(Command command) async {
|
||||
final SubmitInputText submitInputTextCommand = command;
|
||||
final Finder target = await _waitForElement(_createFinder(submitInputTextCommand.finder));
|
||||
final Input input = target.evaluate().single.widget;
|
||||
input.onSubmitted(input.value);
|
||||
return new SubmitInputTextResult(input.value.text);
|
||||
final Finder target = await _waitForElement(_findEditableText(submitInputTextCommand.finder));
|
||||
final EditableTextState editable = _getEditableTextState(target);
|
||||
editable.performAction(TextInputAction.done);
|
||||
return new SubmitInputTextResult(editable.config.controller.value.text);
|
||||
}
|
||||
|
||||
Future<GetTextResult> _getText(Command command) async {
|
||||
|
||||
Reference in New Issue
Block a user