Deprecate invalid InputDecoration.collapsed parameters (#152486)

## Description

This PR is a follow up to https://github.com/flutter/flutter/pull/152165#pullrequestreview-2200072459.
It deprecates two parameters that should not have been added (`floatingLabelBehavior` and `floatingLabelAlignment`) to `InputDecoration.collapsed`. Those parameters are related to the floating label but a collapsed input decoration is not supposed to have labels.

For the dart_fix, I created a new fix file and moved some previous fixes to it.

## Tests

Adds 1 test, updates 1.
This commit is contained in:
Bruno Leroux 2024-07-31 09:59:41 +02:00 committed by GitHub
parent 7133a89c44
commit 0c6b600e76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 325 additions and 244 deletions

View File

@ -0,0 +1,245 @@
# Copyright 2014 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# For details regarding the *Flutter Fix* feature, see
# https://flutter.dev/to/flutter-fix
# Please add new fixes to the top of the file, separated by one blank line
# from other fixes. In a comment, include a link to the PR where the change
# requiring the fix was made.
# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md
# file for instructions on testing these data driven fixes.
# For documentation about this file format, see
# https://dart.dev/go/data-driven-fixes.
# * Fixes in this file are for InputDecoration and InputDecorationTheme from the Material library. *
version: 1
transforms:
# Changes made in https://github.com/flutter/flutter/pull/152486.
- title: "Remove invalid parameter"
date: 2024-07-27
element:
uris: [ 'material.dart' ]
constructor: 'collapsed'
inClass: 'InputDecoration'
changes:
- kind: 'removeParameter'
name: 'floatingLabelBehavior'
# Changes made in https://github.com/flutter/flutter/pull/152486.
- title: "Remove invalid parameter"
date: 2024-07-27
element:
uris: [ 'material.dart' ]
constructor: 'collapsed'
inClass: 'InputDecoration'
changes:
- kind: 'removeParameter'
name: 'floatingLabelAlignment'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Migrate to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
field: 'hasFloatingPlaceholder'
inClass: 'InputDecorationTheme'
changes:
- kind: 'rename'
newName: 'floatingLabelBehavior'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Migrate to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
constructor: ''
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'
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
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'
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
element:
uris: [ 'material.dart' ]
field: 'hasFloatingPlaceholder'
inClass: 'InputDecoration'
changes:
- kind: 'rename'
newName: 'floatingLabelBehavior'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Rename to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
constructor: 'collapsed'
inClass: 'InputDecoration'
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'
variables:
hasFloatingPlaceholder:
kind: 'fragment'
value: 'arguments[hasFloatingPlaceholder]'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Rename to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
constructor: ''
inClass: 'InputDecoration'
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'
variables:
hasFloatingPlaceholder:
kind: 'fragment'
value: 'arguments[hasFloatingPlaceholder]'
# Before adding a new fix: read instructions at the top of this file.

View File

@ -289,208 +289,6 @@ transforms:
- kind: 'removeParameter' - kind: 'removeParameter'
name: 'disabledThumbGapWidth' name: 'disabledThumbGapWidth'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Migrate to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
field: 'hasFloatingPlaceholder'
inClass: 'InputDecorationTheme'
changes:
- kind: 'rename'
newName: 'floatingLabelBehavior'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Migrate to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
constructor: ''
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'
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
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'
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
element:
uris: [ 'material.dart' ]
field: 'hasFloatingPlaceholder'
inClass: 'InputDecoration'
changes:
- kind: 'rename'
newName: 'floatingLabelBehavior'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Rename to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
constructor: 'collapsed'
inClass: 'InputDecoration'
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'
variables:
hasFloatingPlaceholder:
kind: 'fragment'
value: 'arguments[hasFloatingPlaceholder]'
# Changes made in https://github.com/flutter/flutter/pull/46115
- title: "Rename to 'floatingLabelBehavior'"
date: 2020-01-15
element:
uris: [ 'material.dart' ]
constructor: ''
inClass: 'InputDecoration'
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'
variables:
hasFloatingPlaceholder:
kind: 'fragment'
value: 'arguments[hasFloatingPlaceholder]'
# Changes made in https://github.com/flutter/flutter/pull/96115 # Changes made in https://github.com/flutter/flutter/pull/96115
- title: "Migrate 'Icons.pie_chart_outlined' to 'Icons.pie_chart_outline'" - title: "Migrate 'Icons.pie_chart_outlined' to 'Icons.pie_chart_outline'"
date: 2022-01-04 date: 2022-01-04

View File

@ -2629,8 +2629,16 @@ class InputDecoration {
/// Sets the [contentPadding] property to [EdgeInsets.zero]. /// Sets the [contentPadding] property to [EdgeInsets.zero].
const InputDecoration.collapsed({ const InputDecoration.collapsed({
required this.hintText, required this.hintText,
this.floatingLabelBehavior, @Deprecated(
this.floatingLabelAlignment, 'Invalid parameter because a collapsed decoration has no label. '
'This feature was deprecated after v3.24.0-0.1.pre.',
)
FloatingLabelBehavior? floatingLabelBehavior,
@Deprecated(
'Invalid parameter because a collapsed decoration has no label. '
'This feature was deprecated after v3.24.0-0.1.pre.',
)
FloatingLabelAlignment? floatingLabelAlignment,
this.hintStyle, this.hintStyle,
this.hintTextDirection, this.hintTextDirection,
this.hintMaxLines, this.hintMaxLines,
@ -2680,6 +2688,10 @@ class InputDecoration {
disabledBorder = null, disabledBorder = null,
enabledBorder = null, enabledBorder = null,
semanticCounterText = null, semanticCounterText = null,
// ignore: prefer_initializing_formals, (can't use initializing formals for a deprecated parameter).
floatingLabelBehavior = floatingLabelBehavior,
// ignore: prefer_initializing_formals, (can't use initializing formals for a deprecated parameter).
floatingLabelAlignment = floatingLabelAlignment,
alignLabelWithHint = false; alignLabelWithHint = false;
/// 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

View File

@ -0,0 +1,34 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
// Changes made in https://github.com/flutter/flutter/pull/46115.
const InputDecoration inputDecoration = InputDecoration(hasFloatingPlaceholder: true);
InputDecoration(hasFloatingPlaceholder: false);
InputDecoration();
InputDecoration(error: '');
InputDecoration.collapsed(hasFloatingPlaceholder: true);
InputDecoration.collapsed(hasFloatingPlaceholder: false);
InputDecoration.collapsed();
InputDecoration.collapsed(error: '');
inputDecoration.hasFloatingPlaceholder;
const InputDecorationTheme inputDecorationTheme = InputDecorationTheme(hasFloatingPlaceholder: true);
InputDecorationTheme(hasFloatingPlaceholder: false);
InputDecorationTheme();
InputDecorationTheme(error: '');
inputDecorationTheme.hasFloatingPlaceholder;
inputDecorationTheme.copyWith(hasFloatingPlaceholder: false);
inputDecorationTheme.copyWith(hasFloatingPlaceholder: true);
inputDecorationTheme.copyWith();
inputDecorationTheme.copyWith(error: '');
// Changes made in https://github.com/flutter/flutter/pull/152486.
const InputDecoration decoration = InputDecoration.collapsed(
hintText: 'Hint',
floatingLabelAlignment: FloatingLabelAlignment.center,
floatingLabelBehavior: FloatingLabelBehavior.always,
);
}

View File

@ -0,0 +1,32 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
// Changes made in https://github.com/flutter/flutter/pull/46115.
const InputDecoration inputDecoration = InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.never);
InputDecoration();
InputDecoration(error: '');
InputDecoration.collapsed();
InputDecoration.collapsed();
InputDecoration.collapsed();
InputDecoration.collapsed(error: '');
inputDecoration.floatingLabelBehavior;
const InputDecorationTheme inputDecorationTheme = InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.never);
InputDecorationTheme();
InputDecorationTheme(error: '');
inputDecorationTheme.floatingLabelBehavior;
inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.never);
inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.auto);
inputDecorationTheme.copyWith();
inputDecorationTheme.copyWith(error: '');
// Changes made in https://github.com/flutter/flutter/pull/152486.
const InputDecoration decoration = InputDecoration.collapsed(
hintText: 'Hint',
);
}

View File

@ -163,26 +163,6 @@ void main() {
RectangularSliderTrackShape(disabledThumbGapWidth: 2.0); RectangularSliderTrackShape(disabledThumbGapWidth: 2.0);
RectangularSliderTrackShape(error: ''); RectangularSliderTrackShape(error: '');
// Changes made in https://github.com/flutter/flutter/pull/46115
const InputDecoration inputDecoration = InputDecoration(hasFloatingPlaceholder: true);
InputDecoration(hasFloatingPlaceholder: false);
InputDecoration();
InputDecoration(error: '');
InputDecoration.collapsed(hasFloatingPlaceholder: true);
InputDecoration.collapsed(hasFloatingPlaceholder: false);
InputDecoration.collapsed();
InputDecoration.collapsed(error: '');
inputDecoration.hasFloatingPlaceholder;
const InputDecorationTheme inputDecorationTheme = InputDecorationTheme(hasFloatingPlaceholder: true);
InputDecorationTheme(hasFloatingPlaceholder: false);
InputDecorationTheme();
InputDecorationTheme(error: '');
inputDecorationTheme.hasFloatingPlaceholder;
inputDecorationTheme.copyWith(hasFloatingPlaceholder: false);
inputDecorationTheme.copyWith(hasFloatingPlaceholder: true);
inputDecorationTheme.copyWith();
inputDecorationTheme.copyWith(error: '');
// Changes made in https://github.com/flutter/flutter/pull/79160 // Changes made in https://github.com/flutter/flutter/pull/79160
Draggable draggable = Draggable(); Draggable draggable = Draggable();
draggable = Draggable(dragAnchor: DragAnchor.child); draggable = Draggable(dragAnchor: DragAnchor.child);

View File

@ -163,26 +163,6 @@ void main() {
RectangularSliderTrackShape(); RectangularSliderTrackShape();
RectangularSliderTrackShape(error: ''); RectangularSliderTrackShape(error: '');
// Changes made in https://github.com/flutter/flutter/pull/46115
const InputDecoration inputDecoration = InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.never);
InputDecoration();
InputDecoration(error: '');
InputDecoration.collapsed(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecoration.collapsed(floatingLabelBehavior: FloatingLabelBehavior.never);
InputDecoration.collapsed();
InputDecoration.collapsed(error: '');
inputDecoration.floatingLabelBehavior;
const InputDecorationTheme inputDecorationTheme = InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.never);
InputDecorationTheme();
InputDecorationTheme(error: '');
inputDecorationTheme.floatingLabelBehavior;
inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.never);
inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.auto);
inputDecorationTheme.copyWith();
inputDecorationTheme.copyWith(error: '');
// Changes made in https://github.com/flutter/flutter/pull/79160 // Changes made in https://github.com/flutter/flutter/pull/79160
Draggable draggable = Draggable(); Draggable draggable = Draggable();
draggable = Draggable(dragAnchorStrategy: childDragAnchorStrategy); draggable = Draggable(dragAnchorStrategy: childDragAnchorStrategy);