mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Allow updating textAlignVertical (#57033)
This commit is contained in:
parent
26fabcd41b
commit
9f744a9e4c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue