Label unnecessarily ellided (#59807)
This commit is contained in:
committed by
GitHub
parent
65b1956005
commit
b9af6551b2
@@ -986,9 +986,15 @@ class _RenderDecoration extends RenderBox {
|
||||
+ contentPadding.right));
|
||||
// Increase the available width for the label when it is scaled down.
|
||||
final double invertedLabelScale = lerpDouble(1.00, 1 / _kFinalLabelScale, decoration.floatingLabelProgress);
|
||||
final double labelWidth = math.max(0.0, constraints.maxWidth - (
|
||||
_boxSize(icon).width
|
||||
+ contentPadding.left
|
||||
+ _boxSize(prefixIcon).width
|
||||
+ _boxSize(suffixIcon).width
|
||||
+ contentPadding.right));
|
||||
boxToBaseline[label] = _layoutLineBox(
|
||||
label,
|
||||
boxConstraints.copyWith(maxWidth: inputWidth * invertedLabelScale),
|
||||
boxConstraints.copyWith(maxWidth: labelWidth * invertedLabelScale),
|
||||
);
|
||||
boxToBaseline[hint] = _layoutLineBox(
|
||||
hint,
|
||||
|
||||
@@ -4158,4 +4158,64 @@ void main() {
|
||||
|
||||
expect(tester.getTopLeft(find.text(hintText)).dy, topPosition);
|
||||
});
|
||||
|
||||
testWidgets("InputDecorator label width isn't affected by prefix or suffix", (WidgetTester tester) async {
|
||||
const String labelText = 'My Label';
|
||||
const String prefixText = 'The five boxing wizards jump quickly.';
|
||||
const String suffixText = 'Suffix';
|
||||
|
||||
Widget getLabeledInputDecorator(bool showFix) {
|
||||
return MaterialApp(
|
||||
home: Material(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return Theme(
|
||||
data: Theme.of(context),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
icon: const Icon(Icons.assistant),
|
||||
prefixText: showFix ? prefixText : null,
|
||||
suffixText: showFix ? suffixText : null,
|
||||
suffixIcon: const Icon(Icons.threesixty),
|
||||
labelText: labelText,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Build with no prefix or suffix.
|
||||
await tester.pumpWidget(getLabeledInputDecorator(false));
|
||||
|
||||
// Get the width of the label when there is no prefix/suffix.
|
||||
expect(find.text(prefixText), findsNothing);
|
||||
expect(find.text(suffixText), findsNothing);
|
||||
final double labelWidth = tester.getSize(find.text(labelText)).width;
|
||||
|
||||
// Build with a prefix and suffix.
|
||||
await tester.pumpWidget(getLabeledInputDecorator(true));
|
||||
|
||||
// The prefix and suffix exist but aren't visible. They have not affected
|
||||
// the width of the label.
|
||||
expect(find.text(prefixText), findsOneWidget);
|
||||
expect(getOpacity(tester, prefixText), 0.0);
|
||||
expect(find.text(suffixText), findsOneWidget);
|
||||
expect(getOpacity(tester, suffixText), 0.0);
|
||||
expect(tester.getSize(find.text(labelText)).width, labelWidth);
|
||||
|
||||
// Tap to focus.
|
||||
await tester.tap(find.byType(TextField));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The prefix and suffix are visible, and the label is floating and still
|
||||
// hasn't had its width affected.
|
||||
expect(tester.getSize(find.text(labelText)).width, labelWidth);
|
||||
expect(getOpacity(tester, prefixText), 1.0);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user