From 7773d0b020d3ecf22da24a31491c9a17a15fdb94 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Mon, 14 Jun 2021 15:04:04 -0500 Subject: [PATCH] Remove deprecated hasFloatingPlaceholder (#83923) --- packages/flutter/lib/fix_data.yaml | 61 +++++++++++++++ .../lib/src/material/input_border.dart | 5 +- .../lib/src/material/input_decorator.dart | 74 +------------------ .../test/material/input_decorator_test.dart | 6 +- packages/flutter/test_fixes/material.dart | 3 + .../flutter/test_fixes/material.dart.expect | 3 + 6 files changed, 75 insertions(+), 77 deletions(-) diff --git a/packages/flutter/lib/fix_data.yaml b/packages/flutter/lib/fix_data.yaml index 45420f379e..ae3bc5b138 100644 --- a/packages/flutter/lib/fix_data.yaml +++ b/packages/flutter/lib/fix_data.yaml @@ -852,6 +852,67 @@ transforms: kind: 'fragment' value: 'arguments[hasFloatingPlaceholder]' + # Changes made in https://github.com/flutter/flutter/pull/46115 + - title: "Migrate to 'floatingLabelBehavior'" + date: 2020-01-15 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'InputDecorationTheme' + oneOf: + - if: "hasFloatingPlaceholder == 'true'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.auto' + requiredIf: "hasFloatingPlaceholder == 'true'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + - if: "hasFloatingPlaceholder == 'false'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.never' + requiredIf: "hasFloatingPlaceholder == 'false'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + - if: "hasFloatingPlaceholder != 'true' && hasFloatingPlaceholder != 'false'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% hasFloatingPlaceholder %} ? {% FloatingLabelBehavior %}.auto : {% FloatingLabelBehavior %}.never' + requiredIf: "hasFloatingPlaceholder != 'true' && hasFloatingPlaceholder != 'false'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + variables: + hasFloatingPlaceholder: + kind: 'fragment' + value: 'arguments[hasFloatingPlaceholder]' + # Changes made in https://github.com/flutter/flutter/pull/46115 - title: "Migrate to 'floatingLabelBehavior'" date: 2020-01-15 diff --git a/packages/flutter/lib/src/material/input_border.dart b/packages/flutter/lib/src/material/input_border.dart index 2c4695ad87..a7b7b1e05e 100644 --- a/packages/flutter/lib/src/material/input_border.dart +++ b/packages/flutter/lib/src/material/input_border.dart @@ -279,8 +279,9 @@ class OutlineInputBorder extends InputBorder { /// /// See also: /// - /// * [InputDecoration.hasFloatingPlaceholder], which should be set to false - /// when the [borderSide] is [BorderSide.none]. If let as true, the label + /// * [InputDecoration.floatingLabelBehavior], which should be set to + /// [FloatingLabelBehavior.never] when the [borderSide] is + /// [BorderSide.none]. If let as [FloatingLabelBehavior.auto], the label /// will extend beyond the container as if the border were still being /// drawn. const OutlineInputBorder({ diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index b63140c786..d2812c1c67 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -1949,7 +1949,6 @@ class _InputDecoratorState extends State with TickerProviderStat final bool labelIsInitiallyFloating = widget.decoration.floatingLabelBehavior == FloatingLabelBehavior.always || (widget.decoration.floatingLabelBehavior != FloatingLabelBehavior.never && - widget.decoration.hasFloatingPlaceholder && widget._labelShouldWithdraw); _floatingLabelController = AnimationController( @@ -1997,7 +1996,7 @@ class _InputDecoratorState extends State with TickerProviderStat bool get isHovering => widget.isHovering && decoration!.enabled; bool get isEmpty => widget.isEmpty; bool get _floatingLabelEnabled { - return decoration!.hasFloatingPlaceholder && decoration!.floatingLabelBehavior != FloatingLabelBehavior.never; + return decoration!.floatingLabelBehavior != FloatingLabelBehavior.never; } @override @@ -2006,8 +2005,7 @@ class _InputDecoratorState extends State with TickerProviderStat if (widget.decoration != old.decoration) _effectiveDecoration = null; - final bool floatBehaviorChanged = widget.decoration.floatingLabelBehavior != old.decoration.floatingLabelBehavior - || widget.decoration.hasFloatingPlaceholder != old.decoration.hasFloatingPlaceholder; + final bool floatBehaviorChanged = widget.decoration.floatingLabelBehavior != old.decoration.floatingLabelBehavior; if (widget._labelShouldWithdraw != old._labelShouldWithdraw || floatBehaviorChanged) { if (_floatingLabelEnabled @@ -2537,11 +2535,6 @@ class InputDecoration { this.errorText, this.errorStyle, this.errorMaxLines, - @Deprecated( - 'Use floatingLabelBehavior instead. ' - 'This feature was deprecated after v1.13.2.', - ) - this.hasFloatingPlaceholder = true, this.floatingLabelBehavior, this.isCollapsed = false, this.isDense, @@ -2584,11 +2577,6 @@ class InputDecoration { /// Sets the [isCollapsed] property to true. const InputDecoration.collapsed({ required this.hintText, - @Deprecated( - 'Use floatingLabelBehavior instead. ' - 'This feature was deprecated after v1.13.2.', - ) - this.hasFloatingPlaceholder = true, this.floatingLabelBehavior, this.hintStyle, this.hintTextDirection, @@ -2599,10 +2587,6 @@ class InputDecoration { this.border = InputBorder.none, this.enabled = true, }) : assert(enabled != null), - assert( - !(!hasFloatingPlaceholder && identical(floatingLabelBehavior, FloatingLabelBehavior.always)), - 'hasFloatingPlaceholder=false conflicts with FloatingLabelBehavior.always', - ), icon = null, labelText = null, labelStyle = null, @@ -2760,21 +2744,6 @@ class InputDecoration { /// * [helperMaxLines], the equivalent but for the [helperText]. final int? errorMaxLines; - /// Whether the label floats on focus. - /// - /// If this is false, the placeholder disappears when the input has focus or - /// text has been entered. - /// If this is true, the placeholder will rise to the top of the input when - /// the input has focus or text has been entered. - /// - /// Defaults to true. - /// - @Deprecated( - 'Use floatingLabelBehavior instead. ' - 'This feature was deprecated after v1.13.2.', - ) - final bool hasFloatingPlaceholder; - /// {@template flutter.material.inputDecoration.floatingLabelBehavior} /// Defines how the floating label should be displayed. /// @@ -3361,7 +3330,6 @@ class InputDecoration { String? errorText, TextStyle? errorStyle, int? errorMaxLines, - bool? hasFloatingPlaceholder, FloatingLabelBehavior? floatingLabelBehavior, bool? isCollapsed, bool? isDense, @@ -3408,7 +3376,6 @@ class InputDecoration { errorText: errorText ?? this.errorText, errorStyle: errorStyle ?? this.errorStyle, errorMaxLines: errorMaxLines ?? this.errorMaxLines, - hasFloatingPlaceholder: hasFloatingPlaceholder ?? this.hasFloatingPlaceholder, floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior, isCollapsed: isCollapsed ?? this.isCollapsed, isDense: isDense ?? this.isDense, @@ -3456,7 +3423,6 @@ class InputDecoration { hintStyle: hintStyle ?? theme.hintStyle, errorStyle: errorStyle ?? theme.errorStyle, errorMaxLines: errorMaxLines ?? theme.errorMaxLines, - hasFloatingPlaceholder: hasFloatingPlaceholder, floatingLabelBehavior: floatingLabelBehavior ?? theme.floatingLabelBehavior, isCollapsed: isCollapsed, isDense: isDense ?? theme.isDense, @@ -3499,7 +3465,6 @@ class InputDecoration { && other.errorText == errorText && other.errorStyle == errorStyle && other.errorMaxLines == errorMaxLines - && other.hasFloatingPlaceholder == hasFloatingPlaceholder && other.floatingLabelBehavior == floatingLabelBehavior && other.isDense == isDense && other.contentPadding == contentPadding @@ -3549,7 +3514,6 @@ class InputDecoration { errorText, errorStyle, errorMaxLines, - hasFloatingPlaceholder, floatingLabelBehavior, isDense, contentPadding, @@ -3599,7 +3563,6 @@ class InputDecoration { if (errorText != null) 'errorText: "$errorText"', if (errorStyle != null) 'errorStyle: "$errorStyle"', if (errorMaxLines != null) 'errorMaxLines: "$errorMaxLines"', - if (hasFloatingPlaceholder == false) 'hasFloatingPlaceholder: false', if (floatingLabelBehavior != null) 'floatingLabelBehavior: $floatingLabelBehavior', if (isDense ?? false) 'isDense: $isDense', if (contentPadding != null) 'contentPadding: $contentPadding', @@ -3659,11 +3622,6 @@ class InputDecorationTheme with Diagnosticable { this.hintStyle, this.errorStyle, this.errorMaxLines, - @Deprecated( - 'Use floatingLabelBehavior instead. ' - 'This feature was deprecated after v1.13.2.', - ) - this.hasFloatingPlaceholder = true, this.floatingLabelBehavior = FloatingLabelBehavior.auto, this.isDense = false, this.contentPadding, @@ -3686,11 +3644,7 @@ class InputDecorationTheme with Diagnosticable { }) : assert(isDense != null), assert(isCollapsed != null), assert(filled != null), - assert(alignLabelWithHint != null), - assert( - !(!hasFloatingPlaceholder && identical(floatingLabelBehavior, FloatingLabelBehavior.always)), - 'hasFloatingPlaceholder=false conflicts with FloatingLabelBehavior.always', - ); + assert(alignLabelWithHint != null); /// The style to use for [InputDecoration.labelText] when the label is /// above (i.e., vertically adjacent to) the input field. @@ -3748,20 +3702,6 @@ class InputDecorationTheme with Diagnosticable { /// * [helperMaxLines], the equivalent but for the [InputDecoration.helperText]. final int? errorMaxLines; - /// Whether the placeholder text floats to become a label on focus. - /// - /// If this is false, the placeholder disappears when the input has focus or - /// text has been entered. - /// If this is true, the placeholder will rise to the top of the input when - /// the input has focus or text has been entered. - /// - /// Defaults to true. - @Deprecated( - 'Use floatingLabelBehavior instead. ' - 'This feature was deprecated after v1.13.2.', - ) - final bool hasFloatingPlaceholder; - /// {@macro flutter.material.inputDecoration.floatingLabelBehavior} /// /// Defaults to [FloatingLabelBehavior.auto]. @@ -4030,11 +3970,6 @@ class InputDecorationTheme with Diagnosticable { TextStyle? hintStyle, TextStyle? errorStyle, int? errorMaxLines, - @Deprecated( - 'Use floatingLabelBehavior instead. ' - 'This feature was deprecated after v1.13.2.', - ) - bool? hasFloatingPlaceholder, FloatingLabelBehavior? floatingLabelBehavior, bool? isDense, EdgeInsetsGeometry? contentPadding, @@ -4062,7 +3997,6 @@ class InputDecorationTheme with Diagnosticable { hintStyle: hintStyle ?? this.hintStyle, errorStyle: errorStyle ?? this.errorStyle, errorMaxLines: errorMaxLines ?? this.errorMaxLines, - hasFloatingPlaceholder: hasFloatingPlaceholder ?? this.hasFloatingPlaceholder, floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior, isDense: isDense ?? this.isDense, contentPadding: contentPadding ?? this.contentPadding, @@ -4094,7 +4028,6 @@ class InputDecorationTheme with Diagnosticable { hintStyle, errorStyle, errorMaxLines, - hasFloatingPlaceholder, floatingLabelBehavior, isDense, contentPadding, @@ -4162,7 +4095,6 @@ class InputDecorationTheme with Diagnosticable { properties.add(DiagnosticsProperty('hintStyle', hintStyle, defaultValue: defaultTheme.hintStyle)); properties.add(DiagnosticsProperty('errorStyle', errorStyle, defaultValue: defaultTheme.errorStyle)); properties.add(IntProperty('errorMaxLines', errorMaxLines, defaultValue: defaultTheme.errorMaxLines)); - properties.add(DiagnosticsProperty('hasFloatingPlaceholder', hasFloatingPlaceholder, defaultValue: defaultTheme.hasFloatingPlaceholder)); properties.add(DiagnosticsProperty('floatingLabelBehavior', floatingLabelBehavior, defaultValue: defaultTheme.floatingLabelBehavior)); properties.add(DiagnosticsProperty('isDense', isDense, defaultValue: defaultTheme.isDense)); properties.add(DiagnosticsProperty('contentPadding', contentPadding, defaultValue: defaultTheme.contentPadding)); diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 4186c55bca..2fdd19ca0f 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -2894,7 +2894,7 @@ void main() { isEmpty: true, decoration: const InputDecoration( border: OutlineInputBorder(borderSide: BorderSide.none), - hasFloatingPlaceholder: false, + floatingLabelBehavior: FloatingLabelBehavior.never, labelText: 'label', ), ), @@ -2918,7 +2918,7 @@ void main() { // isFocused: false (default) decoration: const InputDecoration( border: OutlineInputBorder(borderSide: BorderSide.none), - hasFloatingPlaceholder: false, + floatingLabelBehavior: FloatingLabelBehavior.never, labelText: 'label', ), ), @@ -4094,7 +4094,6 @@ void main() { helperMaxLines: 6, hintStyle: TextStyle(), errorMaxLines: 5, - hasFloatingPlaceholder: false, floatingLabelBehavior: FloatingLabelBehavior.never, contentPadding: EdgeInsetsDirectional.only(start: 40.0, top: 12.0, bottom: 12.0), prefixStyle: TextStyle(), @@ -4120,7 +4119,6 @@ void main() { 'helperMaxLines: 6', 'hintStyle: TextStyle()', 'errorMaxLines: 5', - 'hasFloatingPlaceholder: false', 'floatingLabelBehavior: FloatingLabelBehavior.never', 'contentPadding: EdgeInsetsDirectional(40.0, 12.0, 0.0, 12.0)', 'prefixStyle: TextStyle()', diff --git a/packages/flutter/test_fixes/material.dart b/packages/flutter/test_fixes/material.dart index 3dd2aa92de..d922a292e7 100644 --- a/packages/flutter/test_fixes/material.dart +++ b/packages/flutter/test_fixes/material.dart @@ -194,6 +194,9 @@ void main() { InputDecorationTheme(hasFloatingPlaceholder: false); InputDecorationTheme(); inputDecorationTheme.hasFloatingPlaceholder; + inputDecorationTheme.copyWith(hasFloatingPlaceholder: false); + inputDecorationTheme.copyWith(hasFloatingPlaceholder: true); + inputDecorationTheme.copyWith(); // Changes made in https://github.com/flutter/flutter/pull/66482 ThemeData(textSelectionColor: Colors.red); diff --git a/packages/flutter/test_fixes/material.dart.expect b/packages/flutter/test_fixes/material.dart.expect index 1df414c826..b6fc693948 100644 --- a/packages/flutter/test_fixes/material.dart.expect +++ b/packages/flutter/test_fixes/material.dart.expect @@ -194,6 +194,9 @@ void main() { InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.never); InputDecorationTheme(); inputDecorationTheme.floatingLabelBehavior; + inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.never); + inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.auto); + inputDecorationTheme.copyWith(); // Changes made in https://github.com/flutter/flutter/pull/66482 ThemeData(textSelectionTheme: TextSelectionThemeData(selectionColor: Colors.red));