Cleanup InputDecoration.collapsed constructor (#152165)
## Description This PR attemps to clarify the `InputDecoration.collapsed` documentation by explaining that it is not meant to be use with helper, label, counter, icons, prefixes and suffixes. It also adds some parameters that make sense for a collapsed decoration (`hintMaxLines`, `hintFadeDuration`, `constraints`). Removing parameters that should not have been added (`floatingLabelBehavior` and `floatingLabelAlignment`) will be part of another PR as it will require deprecations. ## Related Issue Fixes https://github.com/flutter/flutter/issues/61331 ## Tests Adds 3 tests.
This commit is contained in:
parent
1ec4907b40
commit
d8ef702714
@ -2622,19 +2622,26 @@ class InputDecoration {
|
|||||||
///
|
///
|
||||||
/// This type of input decoration does not include a border by default.
|
/// This type of input decoration does not include a border by default.
|
||||||
///
|
///
|
||||||
|
/// A collapsed decoration cannot have [labelText], [errorText], [counter],
|
||||||
|
/// [icon], prefixes, and suffixes.
|
||||||
|
///
|
||||||
/// Sets the [isCollapsed] property to true.
|
/// Sets the [isCollapsed] property to true.
|
||||||
|
/// Sets the [contentPadding] property to [EdgeInsets.zero].
|
||||||
const InputDecoration.collapsed({
|
const InputDecoration.collapsed({
|
||||||
required this.hintText,
|
required this.hintText,
|
||||||
this.floatingLabelBehavior,
|
this.floatingLabelBehavior,
|
||||||
this.floatingLabelAlignment,
|
this.floatingLabelAlignment,
|
||||||
this.hintStyle,
|
this.hintStyle,
|
||||||
this.hintTextDirection,
|
this.hintTextDirection,
|
||||||
|
this.hintMaxLines,
|
||||||
|
this.hintFadeDuration,
|
||||||
this.filled = false,
|
this.filled = false,
|
||||||
this.fillColor,
|
this.fillColor,
|
||||||
this.focusColor,
|
this.focusColor,
|
||||||
this.hoverColor,
|
this.hoverColor,
|
||||||
this.border = InputBorder.none,
|
this.border = InputBorder.none,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
|
this.constraints,
|
||||||
}) : icon = null,
|
}) : icon = null,
|
||||||
iconColor = null,
|
iconColor = null,
|
||||||
label = null,
|
label = null,
|
||||||
@ -2645,8 +2652,6 @@ class InputDecoration {
|
|||||||
helperText = null,
|
helperText = null,
|
||||||
helperStyle = null,
|
helperStyle = null,
|
||||||
helperMaxLines = null,
|
helperMaxLines = null,
|
||||||
hintMaxLines = null,
|
|
||||||
hintFadeDuration = null,
|
|
||||||
error = null,
|
error = null,
|
||||||
errorText = null,
|
errorText = null,
|
||||||
errorStyle = null,
|
errorStyle = null,
|
||||||
@ -2675,8 +2680,7 @@ class InputDecoration {
|
|||||||
disabledBorder = null,
|
disabledBorder = null,
|
||||||
enabledBorder = null,
|
enabledBorder = null,
|
||||||
semanticCounterText = null,
|
semanticCounterText = null,
|
||||||
alignLabelWithHint = false,
|
alignLabelWithHint = false;
|
||||||
constraints = null;
|
|
||||||
|
|
||||||
/// An icon to show before the input field and outside of the decoration's
|
/// An icon to show before the input field and outside of the decoration's
|
||||||
/// container.
|
/// container.
|
||||||
@ -3019,7 +3023,8 @@ class InputDecoration {
|
|||||||
|
|
||||||
/// Whether the decoration is the same size as the input field.
|
/// Whether the decoration is the same size as the input field.
|
||||||
///
|
///
|
||||||
/// A collapsed decoration cannot have [labelText], [errorText], an [icon].
|
/// A collapsed decoration cannot have [labelText], [errorText], [counter],
|
||||||
|
/// [icon], prefixes, and suffixes.
|
||||||
///
|
///
|
||||||
/// To create a collapsed input decoration, use [InputDecoration.collapsed].
|
/// To create a collapsed input decoration, use [InputDecoration.collapsed].
|
||||||
final bool? isCollapsed;
|
final bool? isCollapsed;
|
||||||
@ -3881,7 +3886,7 @@ class InputDecoration {
|
|||||||
/// the current input decoration theme to initialize null [InputDecoration]
|
/// the current input decoration theme to initialize null [InputDecoration]
|
||||||
/// properties.
|
/// properties.
|
||||||
///
|
///
|
||||||
/// The [InputDecoration.applyDefaults] method is used to combine a input
|
/// The [InputDecoration.applyDefaults] method is used to combine an input
|
||||||
/// decoration theme with an [InputDecoration] object.
|
/// decoration theme with an [InputDecoration] object.
|
||||||
@immutable
|
@immutable
|
||||||
class InputDecorationTheme with Diagnosticable {
|
class InputDecorationTheme with Diagnosticable {
|
||||||
|
@ -6523,6 +6523,70 @@ void main() {
|
|||||||
expect(getBorderWeight(tester), 0.0);
|
expect(getBorderWeight(tester), 0.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('InputDecoration.collapsed accepts constraints', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildInputDecorator(
|
||||||
|
decoration: const InputDecoration.collapsed(
|
||||||
|
hintText: hintText,
|
||||||
|
constraints: BoxConstraints.tightFor(width: 200.0, height: 32.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getDecoratorRect(tester).size, const Size(200.0, 32.0));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('InputDecoration.collapsed accepts hintMaxLines', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildInputDecorator(
|
||||||
|
decoration: const InputDecoration.collapsed(
|
||||||
|
hintText: threeLines,
|
||||||
|
hintMaxLines: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const double hintLineHeight = 24.0; // font size = 16 and font height = 1.5.
|
||||||
|
expect(getDecoratorRect(tester).size, const Size(800.0, 2 * hintLineHeight));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('InputDecoration.collapsed accepts hintFadeDuration', (WidgetTester tester) async {
|
||||||
|
// Build once with empty content.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildInputDecorator(
|
||||||
|
isEmpty: true,
|
||||||
|
decoration: const InputDecoration.collapsed(
|
||||||
|
hintText: hintText,
|
||||||
|
hintFadeDuration: Duration(milliseconds: 120),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Hint is visible (opacity 1.0).
|
||||||
|
expect(getHintOpacity(tester), 1.0);
|
||||||
|
|
||||||
|
// Rebuild with non-empty content.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildInputDecorator(
|
||||||
|
decoration: const InputDecoration.collapsed(
|
||||||
|
hintText: hintText,
|
||||||
|
hintFadeDuration: Duration(milliseconds: 120),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// The hint's opacity animates from 1.0 to 0.0.
|
||||||
|
// The animation's default duration is 20ms.
|
||||||
|
await tester.pump(const Duration(milliseconds: 50));
|
||||||
|
final double hintOpacity50ms = getHintOpacity(tester);
|
||||||
|
expect(hintOpacity50ms, inExclusiveRange(0.0, 1.0));
|
||||||
|
await tester.pump(const Duration(milliseconds: 50));
|
||||||
|
final double hintOpacity100ms = getHintOpacity(tester);
|
||||||
|
expect(hintOpacity100ms, inExclusiveRange(0.0, hintOpacity50ms));
|
||||||
|
await tester.pump(const Duration(milliseconds: 50));
|
||||||
|
expect(getHintOpacity(tester), 0.0);
|
||||||
|
});
|
||||||
|
|
||||||
test('InputDecorationTheme.isCollapsed is applied', () {
|
test('InputDecorationTheme.isCollapsed is applied', () {
|
||||||
final InputDecoration decoration = const InputDecoration(
|
final InputDecoration decoration = const InputDecoration(
|
||||||
hintText: 'Hello, Flutter!',
|
hintText: 'Hello, Flutter!',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user