Allow updating textAlignVertical (#57033)

This commit is contained in:
Justin McCandless 2020-05-21 14:37:04 -07:00 committed by GitHub
parent 26fabcd41b
commit 9f744a9e4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 6 deletions

View file

@ -781,20 +781,22 @@ class _RenderDecoration extends RenderBox {
markNeedsLayout();
}
TextAlignVertical get _defaultTextAlignVertical => _isOutlineAligned
? TextAlignVertical.center
: TextAlignVertical.top;
TextAlignVertical get textAlignVertical {
if (_textAlignVertical == null) {
return _isOutlineAligned ? TextAlignVertical.center : TextAlignVertical.top;
return _defaultTextAlignVertical;
}
return _textAlignVertical;
}
TextAlignVertical _textAlignVertical;
set textAlignVertical(TextAlignVertical value) {
assert(value != null);
if (_textAlignVertical == value) {
return;
}
// No need to relayout if the effective value is still the same.
if (textAlignVertical.y == value.y) {
if (textAlignVertical.y == (value?.y ?? _defaultTextAlignVertical.y)) {
_textAlignVertical = value;
return;
}
@ -1707,10 +1709,11 @@ class _Decorator extends RenderObjectWidget {
void updateRenderObject(BuildContext context, _RenderDecoration renderObject) {
renderObject
..decoration = decoration
..textDirection = textDirection
..textBaseline = textBaseline
..expands = expands
..isFocused = isFocused;
..isFocused = isFocused
..textAlignVertical = textAlignVertical
..textBaseline = textBaseline
..textDirection = textDirection;
}
}

View file

@ -3997,4 +3997,43 @@ void main() {
// because the label is not initially floating.
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
});
testWidgets('textAlignVertical can be updated', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/56933
const String hintText = 'hint';
TextAlignVertical alignment = TextAlignVertical.top;
StateSetter setState;
await tester.pumpWidget(
MaterialApp(
home: StatefulBuilder(
builder: (BuildContext context, StateSetter setter) {
setState = setter;
return InputDecorator(
textAlignVertical: alignment,
decoration: const InputDecoration(
hintText: hintText,
),
);
},
),
),
);
final double topPosition = tester.getTopLeft(find.text(hintText)).dy;
setState(() {
alignment = TextAlignVertical.bottom;
});
await tester.pump();
expect(tester.getTopLeft(find.text(hintText)).dy, greaterThan(topPosition));
// Setting textAlignVertical back to null works and reverts to the default.
setState(() {
alignment = null;
});
await tester.pump();
expect(tester.getTopLeft(find.text(hintText)).dy, topPosition);
});
}