Show hint when label is floating (#60394)
This commit is contained in:
committed by
GitHub
parent
e3ad0345ba
commit
533c6b29b4
@@ -2086,9 +2086,14 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
|
||||
}
|
||||
|
||||
// True if the label will be shown and the hint will not.
|
||||
// If we're not focused, there's no value, and labelText was provided,
|
||||
// then the label appears where the hint would.
|
||||
bool get _hasInlineLabel => !widget._labelShouldWithdraw && decoration.labelText != null;
|
||||
// If we're not focused, there's no value, labelText was provided, and
|
||||
// floatingLabelBehavior isn't set to always, then the label appears where the
|
||||
// hint would.
|
||||
bool get _hasInlineLabel {
|
||||
return !widget._labelShouldWithdraw
|
||||
&& decoration.labelText != null
|
||||
&& decoration.floatingLabelBehavior != FloatingLabelBehavior.always;
|
||||
}
|
||||
|
||||
// If the label is a floating placeholder, it's always shown.
|
||||
bool get _shouldShowLabel => _hasInlineLabel || _floatingLabelEnabled;
|
||||
|
||||
@@ -4068,6 +4068,23 @@ void main() {
|
||||
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
|
||||
});
|
||||
|
||||
testWidgets('InputDecorator hint is displayed when floatingLabelBehavior is always', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
buildInputDecorator(
|
||||
// isFocused: false (default)
|
||||
isEmpty: true,
|
||||
decoration: const InputDecoration(
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
hintText: 'hint',
|
||||
labelText: 'label',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(getOpacity(tester, 'hint'), 1.0);
|
||||
});
|
||||
|
||||
testWidgets('InputDecorator floating label width scales when focused', (WidgetTester tester) async {
|
||||
final String longStringA = String.fromCharCodes(List<int>.generate(200, (_) => 65));
|
||||
final String longStringB = String.fromCharCodes(List<int>.generate(200, (_) => 66));
|
||||
|
||||
Reference in New Issue
Block a user