Commit 61760f63 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Rename RawInput to EditableText (#7556)

This patch is part of a series to rationalize our text input classes.

See #7031
parent ab1cd3f8
...@@ -38,7 +38,7 @@ const Curve _kTransitionCurve = Curves.fastOutSlowIn; ...@@ -38,7 +38,7 @@ const Curve _kTransitionCurve = Curves.fastOutSlowIn;
/// ///
/// * [Input], which adds a label, a divider below the text field, and support for /// * [Input], which adds a label, a divider below the text field, and support for
/// an error message. /// an error message.
/// * [RawInput], a text field that does not require [Material] design. /// * [EditableText], a text field that does not require [Material] design.
class InputField extends StatefulWidget { class InputField extends StatefulWidget {
InputField({ InputField({
Key key, Key key,
...@@ -96,13 +96,13 @@ class InputField extends StatefulWidget { ...@@ -96,13 +96,13 @@ class InputField extends StatefulWidget {
} }
class _InputFieldState extends State<InputField> { class _InputFieldState extends State<InputField> {
GlobalKey<RawInputState> _rawInputKey = new GlobalKey<RawInputState>(); GlobalKey<EditableTextState> _editableTextKey = new GlobalKey<EditableTextState>();
GlobalKey<RawInputState> _focusKey = new GlobalKey(debugLabel: "_InputFieldState _focusKey"); GlobalKey<EditableTextState> _focusKey = new GlobalKey(debugLabel: "_InputFieldState _focusKey");
GlobalKey get focusKey => config.focusKey ?? (config.key is GlobalKey ? config.key : _focusKey); GlobalKey get focusKey => config.focusKey ?? (config.key is GlobalKey ? config.key : _focusKey);
void requestKeyboard() { void requestKeyboard() {
_rawInputKey.currentState?.requestKeyboard(); _editableTextKey.currentState?.requestKeyboard();
} }
@override @override
...@@ -120,13 +120,13 @@ class _InputFieldState extends State<InputField> { ...@@ -120,13 +120,13 @@ class _InputFieldState extends State<InputField> {
requestKeyboard(); requestKeyboard();
}, },
// Since the focusKey may have been created here, defer building the // Since the focusKey may have been created here, defer building the
// RawInput until the focusKey's context has been set. This is necessary // EditableText until the focusKey's context has been set. This is
// because the RawInput will check the focus, like Focus.at(focusContext), // necessary because the EditableText will check the focus, like
// when it builds. // Focus.at(focusContext), when it builds.
child: new Builder( child: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new RawInput( return new EditableText(
key: _rawInputKey, key: _editableTextKey,
value: value, value: value,
focusKey: focusKey, focusKey: focusKey,
style: textStyle, style: textStyle,
......
...@@ -50,7 +50,7 @@ TextEditingState _getTextEditingStateFromInputValue(InputValue value) { ...@@ -50,7 +50,7 @@ TextEditingState _getTextEditingStateFromInputValue(InputValue value) {
); );
} }
/// Configuration information for an input field. /// Configuration information for a text input field.
/// ///
/// An [InputValue] contains the text for the input field as well as the /// An [InputValue] contains the text for the input field as well as the
/// selection extent and the composing range. /// selection extent and the composing range.
...@@ -118,15 +118,28 @@ class InputValue { ...@@ -118,15 +118,28 @@ class InputValue {
} }
} }
/// A basic text input control. /// A basic text input field.
/// ///
/// This control is not intended to be used directly. Instead, consider using /// This widget interacts with the [TextInput] service to let the user edit the
/// [Input], which provides focus management and material design. /// text it contains. It also provides scrolling, selection, and cursor
class RawInput extends Scrollable { /// movement. This widget does not provide any focus management (e.g.,
/// tap-to-focus).
///
/// Rather than using this widget directly, consider using [InputField], which
/// adds tap-to-focus and cut, copy, and paste commands, or [TextField], which
/// is a full-featured, material-design text input field with placeholder text,
/// labels, and [Form] integration.
///
/// See also:
///
/// * [InputField], which adds tap-to-focus and cut, copy, and paste commands.
/// * [TextField], which is a full-featured, material-design text input field
/// with placeholder text, labels, and [Form] integration.
class EditableText extends Scrollable {
/// Creates a basic text input control. /// Creates a basic text input control.
/// ///
/// The [value] argument must not be null. /// The [value] argument must not be null.
RawInput({ EditableText({
Key key, Key key,
@required this.value, @required this.value,
this.focusKey, this.focusKey,
...@@ -205,11 +218,11 @@ class RawInput extends Scrollable { ...@@ -205,11 +218,11 @@ class RawInput extends Scrollable {
final ValueChanged<InputValue> onSubmitted; final ValueChanged<InputValue> onSubmitted;
@override @override
RawInputState createState() => new RawInputState(); EditableTextState createState() => new EditableTextState();
} }
/// State for a [RawInput]. /// State for a [EditableText].
class RawInputState extends ScrollableState<RawInput> implements TextInputClient { class EditableTextState extends ScrollableState<EditableText> implements TextInputClient {
Timer _cursorTimer; Timer _cursorTimer;
bool _showCursor = false; bool _showCursor = false;
...@@ -230,7 +243,7 @@ class RawInputState extends ScrollableState<RawInput> implements TextInputClient ...@@ -230,7 +243,7 @@ class RawInputState extends ScrollableState<RawInput> implements TextInputClient
} }
@override @override
void didUpdateConfig(RawInput oldConfig) { void didUpdateConfig(EditableText oldConfig) {
if (_currentValue != config.value) { if (_currentValue != config.value) {
_currentValue = config.value; _currentValue = config.value;
if (_isAttachedToKeyboard) if (_isAttachedToKeyboard)
...@@ -280,7 +293,7 @@ class RawInputState extends ScrollableState<RawInput> implements TextInputClient ...@@ -280,7 +293,7 @@ class RawInputState extends ScrollableState<RawInput> implements TextInputClient
} }
// True if the focus was explicitly requested last frame. This ensures we // True if the focus was explicitly requested last frame. This ensures we
// don't show the keyboard when focus defaults back to the RawInput. // don't show the keyboard when focus defaults back to the EditableText.
bool _requestingFocus = false; bool _requestingFocus = false;
void _attachOrDetachKeyboard(bool focused) { void _attachOrDetachKeyboard(bool focused) {
......
...@@ -14,17 +14,17 @@ import 'framework.dart'; ...@@ -14,17 +14,17 @@ import 'framework.dart';
/// hardware buttons that are represented as keys. Typically used by games and /// hardware buttons that are represented as keys. Typically used by games and
/// other apps that use keyboards for purposes other than text entry. /// other apps that use keyboards for purposes other than text entry.
/// ///
/// For text entry, consider using a [RawInput], which integrates with /// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs). /// on-screen keyboards and input method editors (IMEs).
/// ///
/// See also: /// See also:
/// ///
/// * [RawInput], which should be used instead of this widget for text /// * [EditableText], which should be used instead of this widget for text
/// entry. /// entry.
class RawKeyboardListener extends StatefulWidget { class RawKeyboardListener extends StatefulWidget {
/// Creates a widget that receives raw keyboard events. /// Creates a widget that receives raw keyboard events.
/// ///
/// For text entry, consider using a [RawInput], which integrates with /// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs). /// on-screen keyboards and input method editors (IMEs).
RawKeyboardListener({ RawKeyboardListener({
Key key, Key key,
......
...@@ -8,7 +8,7 @@ import 'package:flutter/scheduler.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/scheduler.dart';
import 'basic.dart'; import 'basic.dart';
import 'container.dart'; import 'container.dart';
import 'editable.dart'; import 'editable_text.dart';
import 'framework.dart'; import 'framework.dart';
import 'gesture_detector.dart'; import 'gesture_detector.dart';
import 'overlay.dart'; import 'overlay.dart';
......
...@@ -18,7 +18,7 @@ export 'src/widgets/container.dart'; ...@@ -18,7 +18,7 @@ export 'src/widgets/container.dart';
export 'src/widgets/debug.dart'; export 'src/widgets/debug.dart';
export 'src/widgets/dismissable.dart'; export 'src/widgets/dismissable.dart';
export 'src/widgets/drag_target.dart'; export 'src/widgets/drag_target.dart';
export 'src/widgets/editable.dart'; export 'src/widgets/editable_text.dart';
export 'src/widgets/focus.dart'; export 'src/widgets/focus.dart';
export 'src/widgets/form.dart'; export 'src/widgets/form.dart';
export 'src/widgets/framework.dart'; export 'src/widgets/framework.dart';
......
...@@ -15,7 +15,7 @@ void main() { ...@@ -15,7 +15,7 @@ void main() {
} }
Future<Null> showKeyboard(WidgetTester tester) async { Future<Null> showKeyboard(WidgetTester tester) async {
RawInputState editable = tester.state(find.byType(RawInput).first); EditableTextState editable = tester.state(find.byType(EditableText).first);
editable.requestKeyboard(); editable.requestKeyboard();
await tester.pump(); await tester.pump();
} }
...@@ -207,7 +207,7 @@ void main() { ...@@ -207,7 +207,7 @@ void main() {
expect(mockTextInput.editingState['text'], equals(initialValue)); expect(mockTextInput.editingState['text'], equals(initialValue));
// initial value should also be visible in the raw input line // initial value should also be visible in the raw input line
RawInputState editableText = tester.state(find.byType(RawInput)); EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.config.value.text, equals(initialValue)); expect(editableText.config.value.text, equals(initialValue));
// sanity check, make sure we can still edit the text and everything updates // sanity check, make sure we can still edit the text and everything updates
......
...@@ -62,14 +62,14 @@ void main() { ...@@ -62,14 +62,14 @@ void main() {
} }
Future<Null> showKeyboard(WidgetTester tester) async { Future<Null> showKeyboard(WidgetTester tester) async {
RawInputState editable = tester.state(find.byType(RawInput).first); EditableTextState editable = tester.state(find.byType(EditableText).first);
editable.requestKeyboard(); editable.requestKeyboard();
await tester.pump(); await tester.pump();
} }
// Returns the first RenderEditable. // Returns the first RenderEditable.
RenderEditable findRenderEditable(WidgetTester tester) { RenderEditable findRenderEditable(WidgetTester tester) {
RenderObject root = tester.renderObject(find.byType(RawInput)); RenderObject root = tester.renderObject(find.byType(EditableText));
expect(root, isNotNull); expect(root, isNotNull);
RenderEditable renderEditable; RenderEditable renderEditable;
...@@ -154,7 +154,7 @@ void main() { ...@@ -154,7 +154,7 @@ void main() {
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
await showKeyboard(tester); await showKeyboard(tester);
RawInputState editableText = tester.state(find.byType(RawInput)); EditableTextState editableText = tester.state(find.byType(EditableText));
// Check that the cursor visibility toggles after each blink interval. // Check that the cursor visibility toggles after each blink interval.
Future<Null> checkCursorToggle() async { Future<Null> checkCursorToggle() async {
......
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