Unverified Commit f21497ee authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Revert "Fix TextField height issues (#27205)" (#29093)

This reverts commit 9e9f48da.
parent a0d1f93b
...@@ -147,8 +147,6 @@ class TextField extends StatefulWidget { ...@@ -147,8 +147,6 @@ class TextField extends StatefulWidget {
this.obscureText = false, this.obscureText = false,
this.autocorrect = true, this.autocorrect = true,
this.maxLines = 1, this.maxLines = 1,
this.minLines,
this.expands = false,
this.maxLength, this.maxLength,
this.maxLengthEnforced = true, this.maxLengthEnforced = true,
this.onChanged, this.onChanged,
...@@ -173,16 +171,6 @@ class TextField extends StatefulWidget { ...@@ -173,16 +171,6 @@ class TextField extends StatefulWidget {
assert(scrollPadding != null), assert(scrollPadding != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
assert(maxLines == null || maxLines > 0), assert(maxLines == null || maxLines > 0),
assert(minLines == null || minLines > 0),
assert(
(maxLines == null) || (minLines == null) || (maxLines >= minLines),
'minLines can\'t be greater than maxLines',
),
assert(expands != null),
assert(
!expands || (maxLines == null && minLines == null),
'minLines and maxLines must be null when expands is true.',
),
assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0), assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0),
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
super(key: key); super(key: key);
...@@ -281,12 +269,6 @@ class TextField extends StatefulWidget { ...@@ -281,12 +269,6 @@ class TextField extends StatefulWidget {
/// {@macro flutter.widgets.editableText.maxLines} /// {@macro flutter.widgets.editableText.maxLines}
final int maxLines; final int maxLines;
/// {@macro flutter.widgets.editableText.minLines}
final int minLines;
/// {@macro flutter.widgets.editableText.expands}
final bool expands;
/// If [maxLength] is set to this value, only the "current input length" /// If [maxLength] is set to this value, only the "current input length"
/// part of the character counter is shown. /// part of the character counter is shown.
static const int noMaxLength = -1; static const int noMaxLength = -1;
...@@ -475,8 +457,6 @@ class TextField extends StatefulWidget { ...@@ -475,8 +457,6 @@ class TextField extends StatefulWidget {
properties.add(DiagnosticsProperty<bool>('obscureText', obscureText, defaultValue: false)); properties.add(DiagnosticsProperty<bool>('obscureText', obscureText, defaultValue: false));
properties.add(DiagnosticsProperty<bool>('autocorrect', autocorrect, defaultValue: true)); properties.add(DiagnosticsProperty<bool>('autocorrect', autocorrect, defaultValue: true));
properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); properties.add(IntProperty('maxLines', maxLines, defaultValue: 1));
properties.add(IntProperty('minLines', minLines, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, defaultValue: true, ifFalse: 'maxLength not enforced')); properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, defaultValue: true, ifFalse: 'maxLength not enforced'));
properties.add(EnumProperty<TextInputAction>('textInputAction', textInputAction, defaultValue: null)); properties.add(EnumProperty<TextInputAction>('textInputAction', textInputAction, defaultValue: null));
...@@ -871,8 +851,6 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -871,8 +851,6 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
obscureText: widget.obscureText, obscureText: widget.obscureText,
autocorrect: widget.autocorrect, autocorrect: widget.autocorrect,
maxLines: widget.maxLines, maxLines: widget.maxLines,
minLines: widget.minLines,
expands: widget.expands,
selectionColor: themeData.textSelectionColor, selectionColor: themeData.textSelectionColor,
selectionControls: widget.selectionEnabled ? textSelectionControls : null, selectionControls: widget.selectionEnabled ? textSelectionControls : null,
onChanged: widget.onChanged, onChanged: widget.onChanged,
...@@ -905,7 +883,6 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -905,7 +883,6 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
textAlign: widget.textAlign, textAlign: widget.textAlign,
isFocused: focusNode.hasFocus, isFocused: focusNode.hasFocus,
isEmpty: controller.value.text.isEmpty, isEmpty: controller.value.text.isEmpty,
expands: widget.expands,
child: child, child: child,
); );
}, },
......
...@@ -1801,9 +1801,9 @@ abstract class RenderBox extends RenderObject { ...@@ -1801,9 +1801,9 @@ abstract class RenderBox extends RenderObject {
testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', double.infinity); testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', double.infinity);
testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', double.infinity); testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', double.infinity);
if (constraints.hasBoundedWidth) if (constraints.hasBoundedWidth)
testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', constraints.maxHeight); testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', constraints.maxWidth);
if (constraints.hasBoundedHeight) if (constraints.hasBoundedHeight)
testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', constraints.maxWidth); testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', constraints.maxHeight);
// TODO(ianh): Test that values are internally consistent in more ways than the above. // TODO(ianh): Test that values are internally consistent in more ways than the above.
......
...@@ -144,8 +144,6 @@ class RenderEditable extends RenderBox { ...@@ -144,8 +144,6 @@ class RenderEditable extends RenderBox {
ValueNotifier<bool> showCursor, ValueNotifier<bool> showCursor,
bool hasFocus, bool hasFocus,
int maxLines = 1, int maxLines = 1,
int minLines,
bool expands = false,
StrutStyle strutStyle, StrutStyle strutStyle,
Color selectionColor, Color selectionColor,
double textScaleFactor = 1.0, double textScaleFactor = 1.0,
...@@ -167,16 +165,6 @@ class RenderEditable extends RenderBox { ...@@ -167,16 +165,6 @@ class RenderEditable extends RenderBox {
}) : assert(textAlign != null), }) : assert(textAlign != null),
assert(textDirection != null, 'RenderEditable created without a textDirection.'), assert(textDirection != null, 'RenderEditable created without a textDirection.'),
assert(maxLines == null || maxLines > 0), assert(maxLines == null || maxLines > 0),
assert(minLines == null || minLines > 0),
assert(
(maxLines == null) || (minLines == null) || (maxLines >= minLines),
'minLines can\'t be greater than maxLines',
),
assert(expands != null),
assert(
!expands || (maxLines == null && minLines == null),
'minLines and maxLines must be null when expands is true.',
),
assert(textScaleFactor != null), assert(textScaleFactor != null),
assert(offset != null), assert(offset != null),
assert(ignorePointer != null), assert(ignorePointer != null),
...@@ -198,8 +186,6 @@ class RenderEditable extends RenderBox { ...@@ -198,8 +186,6 @@ class RenderEditable extends RenderBox {
_showCursor = showCursor ?? ValueNotifier<bool>(false), _showCursor = showCursor ?? ValueNotifier<bool>(false),
_hasFocus = hasFocus ?? false, _hasFocus = hasFocus ?? false,
_maxLines = maxLines, _maxLines = maxLines,
_minLines = minLines,
_expands = expands,
_selectionColor = selectionColor, _selectionColor = selectionColor,
_selection = selection, _selection = selection,
_offset = offset, _offset = offset,
...@@ -705,29 +691,6 @@ class RenderEditable extends RenderBox { ...@@ -705,29 +691,6 @@ class RenderEditable extends RenderBox {
markNeedsTextLayout(); markNeedsTextLayout();
} }
/// {@macro flutter.widgets.editableText.minLines}
int get minLines => _minLines;
int _minLines;
/// The value may be null. If it is not null, then it must be greater than zero.
set minLines(int value) {
assert(value == null || value > 0);
if (minLines == value)
return;
_minLines = value;
markNeedsTextLayout();
}
/// {@macro flutter.widgets.editableText.expands}
bool get expands => _expands;
bool _expands;
set expands(bool value) {
assert(value != null);
if (expands == value)
return;
_expands = value;
markNeedsTextLayout();
}
/// The color to use when painting the selection. /// The color to use when painting the selection.
Color get selectionColor => _selectionColor; Color get selectionColor => _selectionColor;
Color _selectionColor; Color _selectionColor;
...@@ -1187,28 +1150,8 @@ class RenderEditable extends RenderBox { ...@@ -1187,28 +1150,8 @@ class RenderEditable extends RenderBox {
double get preferredLineHeight => _textPainter.preferredLineHeight; double get preferredLineHeight => _textPainter.preferredLineHeight;
double _preferredHeight(double width) { double _preferredHeight(double width) {
// Lock height to maxLines if needed if (maxLines != null)
final bool lockedMax = maxLines != null && minLines == null;
final bool lockedBoth = minLines != null && minLines == maxLines;
final bool singleLine = maxLines == 1;
if (singleLine || lockedMax || lockedBoth) {
return preferredLineHeight * maxLines;
}
// Clamp height to minLines or maxLines if needed
final bool minLimited = minLines != null && minLines > 1;
final bool maxLimited = maxLines != null;
if (minLimited || maxLimited) {
_layoutText(width);
if (minLimited && _textPainter.height < preferredLineHeight * minLines) {
return preferredLineHeight * minLines;
}
if (maxLimited && _textPainter.height > preferredLineHeight * maxLines) {
return preferredLineHeight * maxLines; return preferredLineHeight * maxLines;
}
}
// Set the height based on the content
if (width == double.infinity) { if (width == double.infinity) {
final String text = _textPainter.text.toPlainText(); final String text = _textPainter.text.toPlainText();
int lines = 1; int lines = 1;
...@@ -1670,8 +1613,6 @@ class RenderEditable extends RenderBox { ...@@ -1670,8 +1613,6 @@ class RenderEditable extends RenderBox {
properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor)); properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor));
properties.add(DiagnosticsProperty<ValueNotifier<bool>>('showCursor', showCursor)); properties.add(DiagnosticsProperty<ValueNotifier<bool>>('showCursor', showCursor));
properties.add(IntProperty('maxLines', maxLines)); properties.add(IntProperty('maxLines', maxLines));
properties.add(IntProperty('minLines', minLines));
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
properties.add(DiagnosticsProperty<Color>('selectionColor', selectionColor)); properties.add(DiagnosticsProperty<Color>('selectionColor', selectionColor));
properties.add(DoubleProperty('textScaleFactor', textScaleFactor)); properties.add(DoubleProperty('textScaleFactor', textScaleFactor));
properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null)); properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null));
......
...@@ -278,8 +278,6 @@ class EditableText extends StatefulWidget { ...@@ -278,8 +278,6 @@ class EditableText extends StatefulWidget {
this.locale, this.locale,
this.textScaleFactor, this.textScaleFactor,
this.maxLines = 1, this.maxLines = 1,
this.minLines,
this.expands = false,
this.autofocus = false, this.autofocus = false,
this.selectionColor, this.selectionColor,
this.selectionControls, this.selectionControls,
...@@ -312,16 +310,6 @@ class EditableText extends StatefulWidget { ...@@ -312,16 +310,6 @@ class EditableText extends StatefulWidget {
assert(backgroundCursorColor != null), assert(backgroundCursorColor != null),
assert(textAlign != null), assert(textAlign != null),
assert(maxLines == null || maxLines > 0), assert(maxLines == null || maxLines > 0),
assert(minLines == null || minLines > 0),
assert(
(maxLines == null) || (minLines == null) || (maxLines >= minLines),
'minLines can\'t be greater than maxLines',
),
assert(expands != null),
assert(
!expands || (maxLines == null && minLines == null),
'minLines and maxLines must be null when expands is true.',
),
assert(autofocus != null), assert(autofocus != null),
assert(rendererIgnoresPointer != null), assert(rendererIgnoresPointer != null),
assert(scrollPadding != null), assert(scrollPadding != null),
...@@ -477,78 +465,12 @@ class EditableText extends StatefulWidget { ...@@ -477,78 +465,12 @@ class EditableText extends StatefulWidget {
/// container will start with enough vertical space for one line and /// container will start with enough vertical space for one line and
/// automatically grow to accommodate additional lines as they are entered. /// automatically grow to accommodate additional lines as they are entered.
/// ///
/// If this is not null, the value must be greater than zero, and it will lock /// If it is not null, the value must be greater than zero. If it is greater
/// the input to the given number of lines and take up enough horizontal space /// than 1, it will take up enough horizontal space to accommodate that number
/// to accommodate that number of lines. Setting [minLines] as well allows the /// of lines.
/// input to grow between the indicated range.
///
/// The full set of behaviors possible with [minLines] and [maxLines] are as
/// follows. These examples apply equally to `TextField`, `TextFormField`, and
/// `EditableText`.
///
/// Input that occupies a single line and scrolls horizontally as needed.
/// ```dart
/// TextField()
/// ```
///
/// Input whose height grows from one line up to as many lines as needed for
/// the text that was entered. If a height limit is imposed by its parent, it
/// will scroll vertically when its height reaches that limit.
/// ```dart
/// TextField(maxLines: null)
/// ```
///
/// The input's height is large enough for the given number of lines. If
/// additional lines are entered the input scrolls vertically.
/// ```dart
/// TextField(maxLines: 2)
/// ```
///
/// Input whose height grows with content between a min and max. An infinite
/// max is possible with `maxLines: null`.
/// ```dart
/// TextField(minLines: 2, maxLines: 4)
/// ```
/// {@endtemplate} /// {@endtemplate}
final int maxLines; final int maxLines;
/// {@template flutter.widgets.editableText.minLines}
/// The minimum number of lines to occupy when the content spans fewer lines.
/// When [maxLines] is set as well, the height will grow between the indicated
/// range of lines. When [maxLines] is null, it will grow as high as needed,
/// starting from [minLines].
///
/// See the examples in [maxLines] for the complete picture of how [maxLines]
/// and [minLines] interact to produce various behaviors.
///
/// Defaults to null.
/// {@endtemplate}
final int minLines;
/// {@template flutter.widgets.editableText.expands}
/// Whether this widget's height will be sized to fill its parent.
///
/// If set to true and wrapped in a parent widget like [Expanded] or
/// [SizedBox], the input will expand to fill the parent.
///
/// [maxLines] and [minLines] must both be null when this is set to true,
/// otherwise an error is thrown.
///
/// Defaults to false.
///
/// See the examples in [maxLines] for the complete picture of how [maxLines],
/// [minLines], and [expands] interact to produce various behaviors.
///
/// Input that matches the height of its parent
/// ```dart
/// Expanded(
/// child: TextField(maxLines: null, expands: true),
/// )
/// ```
/// {@endtemplate}
final bool expands;
/// {@template flutter.widgets.editableText.autofocus} /// {@template flutter.widgets.editableText.autofocus}
/// Whether this text field should focus itself if nothing else is already /// Whether this text field should focus itself if nothing else is already
/// focused. /// focused.
...@@ -754,8 +676,6 @@ class EditableText extends StatefulWidget { ...@@ -754,8 +676,6 @@ class EditableText extends StatefulWidget {
properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null)); properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null));
properties.add(DoubleProperty('textScaleFactor', textScaleFactor, defaultValue: null)); properties.add(DoubleProperty('textScaleFactor', textScaleFactor, defaultValue: null));
properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); properties.add(IntProperty('maxLines', maxLines, defaultValue: 1));
properties.add(IntProperty('minLines', minLines, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false)); properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false));
properties.add(DiagnosticsProperty<TextInputType>('keyboardType', keyboardType, defaultValue: null)); properties.add(DiagnosticsProperty<TextInputType>('keyboardType', keyboardType, defaultValue: null));
} }
...@@ -875,7 +795,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -875,7 +795,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
// If this is a multiline EditableText, do nothing for a "newline" // If this is a multiline EditableText, do nothing for a "newline"
// action; The newline is already inserted. Otherwise, finalize // action; The newline is already inserted. Otherwise, finalize
// editing. // editing.
if (!_isMultiline) if (widget.maxLines == 1)
_finalizeEditing(true); _finalizeEditing(true);
break; break;
case TextInputAction.done: case TextInputAction.done:
...@@ -1413,8 +1333,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -1413,8 +1333,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
: _cursorVisibilityNotifier, : _cursorVisibilityNotifier,
hasFocus: _hasFocus, hasFocus: _hasFocus,
maxLines: widget.maxLines, maxLines: widget.maxLines,
minLines: widget.minLines,
expands: widget.expands,
strutStyle: widget.strutStyle, strutStyle: widget.strutStyle,
selectionColor: widget.selectionColor, selectionColor: widget.selectionColor,
textScaleFactor: widget.textScaleFactor ?? MediaQuery.textScaleFactorOf(context), textScaleFactor: widget.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
...@@ -1485,8 +1403,6 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -1485,8 +1403,6 @@ class _Editable extends LeafRenderObjectWidget {
this.showCursor, this.showCursor,
this.hasFocus, this.hasFocus,
this.maxLines, this.maxLines,
this.minLines,
this.expands,
this.strutStyle, this.strutStyle,
this.selectionColor, this.selectionColor,
this.textScaleFactor, this.textScaleFactor,
...@@ -1517,8 +1433,6 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -1517,8 +1433,6 @@ class _Editable extends LeafRenderObjectWidget {
final ValueNotifier<bool> showCursor; final ValueNotifier<bool> showCursor;
final bool hasFocus; final bool hasFocus;
final int maxLines; final int maxLines;
final int minLines;
final bool expands;
final StrutStyle strutStyle; final StrutStyle strutStyle;
final Color selectionColor; final Color selectionColor;
final double textScaleFactor; final double textScaleFactor;
...@@ -1548,8 +1462,6 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -1548,8 +1462,6 @@ class _Editable extends LeafRenderObjectWidget {
showCursor: showCursor, showCursor: showCursor,
hasFocus: hasFocus, hasFocus: hasFocus,
maxLines: maxLines, maxLines: maxLines,
minLines: minLines,
expands: expands,
strutStyle: strutStyle, strutStyle: strutStyle,
selectionColor: selectionColor, selectionColor: selectionColor,
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
...@@ -1580,8 +1492,6 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -1580,8 +1492,6 @@ class _Editable extends LeafRenderObjectWidget {
..showCursor = showCursor ..showCursor = showCursor
..hasFocus = hasFocus ..hasFocus = hasFocus
..maxLines = maxLines ..maxLines = maxLines
..minLines = minLines
..expands = expands
..strutStyle = strutStyle ..strutStyle = strutStyle
..selectionColor = selectionColor ..selectionColor = selectionColor
..textScaleFactor = textScaleFactor ..textScaleFactor = textScaleFactor
......
...@@ -993,100 +993,6 @@ void main() { ...@@ -993,100 +993,6 @@ void main() {
expect(tester.getTopRight(find.text('text')).dx, lessThanOrEqualTo(tester.getTopRight(find.byKey(sKey)).dx)); expect(tester.getTopRight(find.text('text')).dx, lessThanOrEqualTo(tester.getTopRight(find.byKey(sKey)).dx));
}); });
testWidgets('InputDecorator tall prefix', (WidgetTester tester) async {
const Key pKey = Key('p');
await tester.pumpWidget(
buildInputDecorator(
// isEmpty: false (default)
// isFocused: false (default)
decoration: InputDecoration(
prefix: Container(
key: pKey,
height: 100,
width: 10,
),
filled: true,
),
// Set the fontSize so that everything works out to whole numbers.
child: const Text(
'text',
style: TextStyle(fontFamily: 'Ahem', fontSize: 20.0),
),
),
);
// Overall height for this InputDecorator is ~127.2dps because
// the prefix is 100dps tall, but it aligns with the input's baseline,
// overlapping the input a bit.
// 12 - top padding
// 100 - total height of prefix
// -16 - input prefix overlap (distance input top to baseline, not exact)
// 20 - input text (ahem font size 16dps)
// 0 - bottom prefix/suffix padding
// 12 - bottom padding
expect(tester.getSize(find.byType(InputDecorator)).width, 800.0);
expect(tester.getSize(find.byType(InputDecorator)).height, closeTo(128.0, .0001));
expect(tester.getSize(find.text('text')).height, 20.0);
expect(tester.getSize(find.byKey(pKey)).height, 100.0);
expect(tester.getTopLeft(find.text('text')).dy, closeTo(96, .0001)); // 12 + 100 - 16
expect(tester.getTopLeft(find.byKey(pKey)).dy, 12.0);
// layout is a row: [prefix text suffix]
expect(tester.getTopLeft(find.byKey(pKey)).dx, 12.0);
expect(tester.getTopRight(find.byKey(pKey)).dx, tester.getTopLeft(find.text('text')).dx);
});
testWidgets('InputDecorator tall prefix with border', (WidgetTester tester) async {
const Key pKey = Key('p');
await tester.pumpWidget(
buildInputDecorator(
// isEmpty: false (default)
// isFocused: false (default)
decoration: InputDecoration(
border: const OutlineInputBorder(),
prefix: Container(
key: pKey,
height: 100,
width: 10,
),
filled: true,
),
// Set the fontSize so that everything works out to whole numbers.
child: const Text(
'text',
style: TextStyle(fontFamily: 'Ahem', fontSize: 20.0),
),
),
);
// Overall height for this InputDecorator is ~127.2dps because
// the prefix is 100dps tall, but it aligns with the input's baseline,
// overlapping the input a bit.
// 24 - top padding
// 100 - total height of prefix
// -16 - input prefix overlap (distance input top to baseline, not exact)
// 20 - input text (ahem font size 16dps)
// 0 - bottom prefix/suffix padding
// 16 - bottom padding
// When a border is present, the input text and prefix/suffix are centered
// within the input. Here, that will be content of height 106, including 2
// extra pixels of space, centered within an input of height 144. That gives
// 19 pixels of space on each side of the content, so the prefix is
// positioned at 19, and the text is at 19+100-16=103.
expect(tester.getSize(find.byType(InputDecorator)).width, 800.0);
expect(tester.getSize(find.byType(InputDecorator)).height, closeTo(144, .0001));
expect(tester.getSize(find.text('text')).height, 20.0);
expect(tester.getSize(find.byKey(pKey)).height, 100.0);
expect(tester.getTopLeft(find.text('text')).dy, closeTo(103, .0001));
expect(tester.getTopLeft(find.byKey(pKey)).dy, 19.0);
// layout is a row: [prefix text suffix]
expect(tester.getTopLeft(find.byKey(pKey)).dx, 12.0);
expect(tester.getTopRight(find.byKey(pKey)).dx, tester.getTopLeft(find.text('text')).dx);
});
testWidgets('InputDecorator prefixIcon/suffixIcon', (WidgetTester tester) async { testWidgets('InputDecorator prefixIcon/suffixIcon', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
buildInputDecorator( buildInputDecorator(
...@@ -1169,6 +1075,7 @@ void main() { ...@@ -1169,6 +1075,7 @@ void main() {
expect(tester.getTopLeft(find.byKey(prefixKey)).dy, 0.0); expect(tester.getTopLeft(find.byKey(prefixKey)).dy, 0.0);
}); });
testWidgets('counter text has correct right margin - LTR, not dense', (WidgetTester tester) async { testWidgets('counter text has correct right margin - LTR, not dense', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
buildInputDecorator( buildInputDecorator(
......
...@@ -6,40 +6,24 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,40 +6,24 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() { void main() {
testWidgets('Dialog interaction', (WidgetTester tester) async { testWidgets('Request focus shows keyboard', (WidgetTester tester) async {
expect(tester.testTextInput.isVisible, isFalse); final FocusNode focusNode = FocusNode();
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( MaterialApp(
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
autofocus: true, focusNode: focusNode,
), ),
), ),
), ),
), ),
); );
expect(tester.testTextInput.isVisible, isTrue);
final BuildContext context = tester.element(find.byType(TextField));
showDialog<void>(
context: context,
builder: (BuildContext context) => const SimpleDialog(title: Text('Dialog')),
);
await tester.pump();
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
Navigator.of(tester.element(find.text('Dialog'))).pop(); FocusScope.of(tester.element(find.byType(TextField))).requestFocus(focusNode);
await tester.pump();
expect(tester.testTextInput.isVisible, isFalse);
await tester.tap(find.byType(TextField));
await tester.idle(); await tester.idle();
expect(tester.testTextInput.isVisible, isTrue); expect(tester.testTextInput.isVisible, isTrue);
...@@ -49,26 +33,21 @@ void main() { ...@@ -49,26 +33,21 @@ void main() {
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
}); });
testWidgets('Request focus shows keyboard', (WidgetTester tester) async { testWidgets('Autofocus shows keyboard', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); expect(tester.testTextInput.isVisible, isFalse);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( const MaterialApp(
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
focusNode: focusNode, autofocus: true,
), ),
), ),
), ),
), ),
); );
expect(tester.testTextInput.isVisible, isFalse);
FocusScope.of(tester.element(find.byType(TextField))).requestFocus(focusNode);
await tester.idle();
expect(tester.testTextInput.isVisible, isTrue); expect(tester.testTextInput.isVisible, isTrue);
await tester.pumpWidget(Container()); await tester.pumpWidget(Container());
...@@ -76,21 +55,33 @@ void main() { ...@@ -76,21 +55,33 @@ void main() {
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
}); });
testWidgets('Autofocus shows keyboard', (WidgetTester tester) async { testWidgets('Tap shows keyboard', (WidgetTester tester) async {
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(),
autofocus: true,
),
), ),
), ),
), ),
); );
expect(tester.testTextInput.isVisible, isFalse);
await tester.tap(find.byType(TextField));
await tester.idle();
expect(tester.testTextInput.isVisible, isTrue);
tester.testTextInput.hide();
expect(tester.testTextInput.isVisible, isFalse);
await tester.tap(find.byType(TextField));
await tester.idle();
expect(tester.testTextInput.isVisible, isTrue); expect(tester.testTextInput.isVisible, isTrue);
await tester.pumpWidget(Container()); await tester.pumpWidget(Container());
...@@ -98,27 +89,36 @@ void main() { ...@@ -98,27 +89,36 @@ void main() {
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
}); });
testWidgets('Tap shows keyboard', (WidgetTester tester) async { testWidgets('Dialog interaction', (WidgetTester tester) async {
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Material( home: Material(
child: Center( child: Center(
child: TextField(), child: TextField(
autofocus: true,
),
), ),
), ),
), ),
); );
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isTrue);
await tester.tap(find.byType(TextField)); final BuildContext context = tester.element(find.byType(TextField));
await tester.idle();
expect(tester.testTextInput.isVisible, isTrue); showDialog<void>(
context: context,
builder: (BuildContext context) => const SimpleDialog(title: Text('Dialog')),
);
tester.testTextInput.hide(); await tester.pump();
expect(tester.testTextInput.isVisible, isFalse);
Navigator.of(tester.element(find.text('Dialog'))).pop();
await tester.pump();
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
......
...@@ -56,7 +56,6 @@ void main() { ...@@ -56,7 +56,6 @@ void main() {
' │ cursorColor: null\n' ' │ cursorColor: null\n'
' │ showCursor: ValueNotifier<bool>#00000(false)\n' ' │ showCursor: ValueNotifier<bool>#00000(false)\n'
' │ maxLines: 1\n' ' │ maxLines: 1\n'
' │ minLines: null\n'
' │ selectionColor: null\n' ' │ selectionColor: null\n'
' │ textScaleFactor: 1.0\n' ' │ textScaleFactor: 1.0\n'
' │ locale: ja_JP\n' ' │ locale: ja_JP\n'
......
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