Skip to content

Commit

Permalink
Re-land "Deprecate WhitelistingTextInputFormatter and BlacklistingTex…
Browse files Browse the repository at this point in the history
…tInputFormatter (flutter#59120)" (flutter#59876)

This relands flutter#59120, which was reverted in flutter#59870.
  • Loading branch information
christopherfujino authored and zljj0818 committed Jun 22, 2020
1 parent b34406d commit 4c6971b
Show file tree
Hide file tree
Showing 29 changed files with 662 additions and 158 deletions.
3 changes: 3 additions & 0 deletions analysis_options.yaml
Expand Up @@ -29,6 +29,9 @@ analyzer:
missing_return: warning
# allow having TODOs in the code
todo: ignore
# allow self-reference to deprecated members (we do this because otherwise we have
# to annotate every member in every test, assert, etc, when we deprecate something)
deprecated_member_use_from_same_package: ignore
# Ignore analyzer hints for updating pubspecs when using Future or
# Stream and not importing dart:async
# Please see https://github.com/flutter/flutter/pull/24528 for details.
Expand Down
11 changes: 9 additions & 2 deletions dev/bots/analyze.dart
Expand Up @@ -135,7 +135,7 @@ Future<void> run(List<String> arguments) async {
final RegExp _findDeprecationPattern = RegExp(r'@[Dd]eprecated');
final RegExp _deprecationPattern1 = RegExp(r'^( *)@Deprecated\($'); // ignore: flutter_deprecation_syntax (see analyze.dart)
final RegExp _deprecationPattern2 = RegExp(r"^ *'(.+) '$");
final RegExp _deprecationPattern3 = RegExp(r"^ *'This feature was deprecated after v([0-9]+)\.([0-9]+)\.([0-9]+)\.'$");
final RegExp _deprecationPattern3 = RegExp(r"^ *'This feature was deprecated after v([0-9]+)\.([0-9]+)\.([0-9]+)(\-[0-9]+\.[0-9]+\.pre)?\.'$");
final RegExp _deprecationPattern4 = RegExp(r'^ *\)$');

/// Some deprecation notices are special, for example they're used to annotate members that
Expand Down Expand Up @@ -182,14 +182,21 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
if (message == null) {
final String firstChar = String.fromCharCode(match2[1].runes.first);
if (firstChar.toUpperCase() != firstChar)
throw 'Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide.';
throw 'Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo';
}
message = match2[1];
lineNumber += 1;
if (lineNumber >= lines.length)
throw 'Incomplete deprecation notice.';
match3 = _deprecationPattern3.firstMatch(lines[lineNumber]);
} while (match3 == null);
final int v1 = int.parse(match3[1]);
final int v2 = int.parse(match3[2]);
final bool hasV4 = match3[4] != null;
if (v1 > 1 || (v1 == 1 && v2 >= 20)) {
if (!hasV4)
throw 'Deprecation notice does not accurately indicate a dev branch version number; please see https://flutter.dev/docs/development/tools/sdk/releases to find the latest dev build version number.';
}
if (!message.endsWith('.') && !message.endsWith('!') && !message.endsWith('?'))
throw 'Deprecation notice should be a grammatically correct sentence and end with a period.';
if (!lines[lineNumber].startsWith("$indent '"))
Expand Down
Expand Up @@ -55,6 +55,42 @@ void test10() { }

@Deprecated(
'URLs are not required. '
'This feature was deprecated after v2.0.0.'
'This feature was deprecated after v1.0.0.'
)
void test11() { }

@Deprecated(
'Version number test (should fail). '
'This feature was deprecated after v1.19.0.'
)
void test12() { }

@Deprecated(
'Version number test (should fail). '
'This feature was deprecated after v1.20.0.'
)
void test13() { }

@Deprecated(
'Version number test (should fail). '
'This feature was deprecated after v1.21.0.'
)
void test14() { }

@Deprecated(
'Version number test (should fail). '
'This feature was deprecated after v3.1.0.'
)
void test15() { }

@Deprecated(
'Version number test (should be fine). '
'This feature was deprecated after v0.1.0.'
)
void test16() { }

@Deprecated(
'Version number test (should be fine). '
'This feature was deprecated after v1.20.0-1.0.pre.'
)
void test17() { }
7 changes: 6 additions & 1 deletion dev/bots/test/analyze_test.dart
Expand Up @@ -41,15 +41,20 @@ void main() {
+
(
'test/analyze-test-input/root/packages/foo/deprecation.dart:12: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:18: Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:18: Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: STYLE_GUIDE_URL\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:25: Deprecation notice should be a grammatically correct sentence and end with a period.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:29: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:32: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:37: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:41: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:48: End of deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:51: Unexpected deprecation notice indent.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:70: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:76: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:82: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.\n'
.replaceAll('/', Platform.isWindows ? r'\' : '/')
.replaceAll('STYLE_GUIDE_URL', 'https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo')
.replaceAll('RELEASES_URL', 'https://flutter.dev/docs/development/tools/sdk/releases')
)
+
'See: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes\n'
Expand Down
Expand Up @@ -217,7 +217,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
validator: _validatePhoneNumber,
// TextInputFormatters are applied in sequence.
inputFormatters: <TextInputFormatter> [
WhitelistingTextInputFormatter.digitsOnly,
FilteringTextInputFormatter.digitsOnly,
// Fit the validating format.
_phoneNumberFormatter,
],
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/cupertino/nav_bar.dart
Expand Up @@ -463,7 +463,7 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> {
);

final Color actionsForegroundColor = CupertinoDynamicColor.resolve(
widget.actionsForegroundColor, // ignore: deprecated_member_use_from_same_package
widget.actionsForegroundColor,
context,
);
if (!widget.transitionBetweenRoutes || !_isTransitionable(context)) {
Expand Down Expand Up @@ -694,8 +694,8 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
@override
Widget build(BuildContext context) {
// Lint ignore to maintain backward compatibility.
final Color actionsForegroundColor = CupertinoDynamicColor.resolve(widget.actionsForegroundColor, context) // ignore: deprecated_member_use_from_same_package
?? CupertinoTheme.of(context).primaryColor;
final Color actionsForegroundColor = CupertinoDynamicColor.resolve(widget.actionsForegroundColor, context)
?? CupertinoTheme.of(context).primaryColor;

final _NavigationBarStaticComponents components = _NavigationBarStaticComponents(
keys: keys,
Expand Down
5 changes: 0 additions & 5 deletions packages/flutter/lib/src/material/dialog.dart
Expand Up @@ -4,11 +4,6 @@

// @dart = 2.8

// TODO(shihaohong): remove ignoring deprecated member use analysis
// when AlertDialog.scrollable parameter is removed. See
// https://flutter.dev/go/scrollable-alert-dialog for more details.
// ignore_for_file: deprecated_member_use_from_same_package

import 'dart:async';

import 'package:flutter/foundation.dart';
Expand Down
20 changes: 3 additions & 17 deletions packages/flutter/lib/src/material/input_decorator.dart
Expand Up @@ -1927,7 +1927,6 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat

final bool labelIsInitiallyFloating = widget.decoration.floatingLabelBehavior == FloatingLabelBehavior.always
|| (widget.decoration.floatingLabelBehavior != FloatingLabelBehavior.never &&
// ignore: deprecated_member_use_from_same_package
widget.decoration.hasFloatingPlaceholder &&
widget._labelShouldWithdraw);

Expand Down Expand Up @@ -1976,7 +1975,6 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
bool get isHovering => widget.isHovering && decoration.enabled;
bool get isEmpty => widget.isEmpty;
bool get _floatingLabelEnabled {
// ignore: deprecated_member_use_from_same_package
return decoration.hasFloatingPlaceholder && decoration.floatingLabelBehavior != FloatingLabelBehavior.never;
}

Expand All @@ -1987,7 +1985,6 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
_effectiveDecoration = null;

final bool floatBehaviorChanged = widget.decoration.floatingLabelBehavior != old.decoration.floatingLabelBehavior
// ignore: deprecated_member_use_from_same_package
|| widget.decoration.hasFloatingPlaceholder != old.decoration.hasFloatingPlaceholder;

if (widget._labelShouldWithdraw != old._labelShouldWithdraw || floatBehaviorChanged) {
Expand Down Expand Up @@ -2520,7 +2517,7 @@ class InputDecoration {
'Use floatingLabelBehavior instead. '
'This feature was deprecated after v1.13.2.'
)
this.hasFloatingPlaceholder = true, // ignore: deprecated_member_use_from_same_package
this.hasFloatingPlaceholder = true,
this.floatingLabelBehavior = FloatingLabelBehavior.auto,
this.isCollapsed = false,
this.isDense,
Expand Down Expand Up @@ -2566,7 +2563,6 @@ class InputDecoration {
'Use floatingLabelBehavior instead. '
'This feature was deprecated after v1.13.2.'
)
// ignore: deprecated_member_use_from_same_package
this.hasFloatingPlaceholder = true,
this.floatingLabelBehavior = FloatingLabelBehavior.auto,
this.hintStyle,
Expand All @@ -2577,9 +2573,8 @@ class InputDecoration {
this.border = InputBorder.none,
this.enabled = true,
}) : assert(enabled != null),
// ignore: deprecated_member_use_from_same_package
assert(!(!hasFloatingPlaceholder && identical(floatingLabelBehavior, FloatingLabelBehavior.always)),
'hasFloatingPlaceholder=false conflicts with FloatingLabelBehavior.always'),
'hasFloatingPlaceholder=false conflicts with FloatingLabelBehavior.always'),
icon = null,
labelText = null,
labelStyle = null,
Expand Down Expand Up @@ -3372,7 +3367,6 @@ class InputDecoration {
errorText: errorText ?? this.errorText,
errorStyle: errorStyle ?? this.errorStyle,
errorMaxLines: errorMaxLines ?? this.errorMaxLines,
// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: hasFloatingPlaceholder ?? this.hasFloatingPlaceholder,
floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior,
isCollapsed: isCollapsed ?? this.isCollapsed,
Expand Down Expand Up @@ -3420,7 +3414,6 @@ class InputDecoration {
hintStyle: hintStyle ?? theme.hintStyle,
errorStyle: errorStyle ?? theme.errorStyle,
errorMaxLines: errorMaxLines ?? theme.errorMaxLines,
// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: hasFloatingPlaceholder ?? theme.hasFloatingPlaceholder,
floatingLabelBehavior: floatingLabelBehavior ?? theme.floatingLabelBehavior,
isCollapsed: isCollapsed ?? theme.isCollapsed,
Expand Down Expand Up @@ -3462,7 +3455,6 @@ class InputDecoration {
&& other.errorText == errorText
&& other.errorStyle == errorStyle
&& other.errorMaxLines == errorMaxLines
// ignore: deprecated_member_use_from_same_package
&& other.hasFloatingPlaceholder == hasFloatingPlaceholder
&& other.floatingLabelBehavior == floatingLabelBehavior
&& other.isDense == isDense
Expand Down Expand Up @@ -3511,7 +3503,7 @@ class InputDecoration {
errorText,
errorStyle,
errorMaxLines,
hasFloatingPlaceholder,// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder,
floatingLabelBehavior,
isDense,
contentPadding,
Expand Down Expand Up @@ -3560,7 +3552,6 @@ class InputDecoration {
if (errorText != null) 'errorText: "$errorText"',
if (errorStyle != null) 'errorStyle: "$errorStyle"',
if (errorMaxLines != null) 'errorMaxLines: "$errorMaxLines"',
// ignore: deprecated_member_use_from_same_package
if (hasFloatingPlaceholder == false) 'hasFloatingPlaceholder: false',
if (floatingLabelBehavior != null) 'floatingLabelBehavior: $floatingLabelBehavior',
if (isDense ?? false) 'isDense: $isDense',
Expand Down Expand Up @@ -3624,7 +3615,6 @@ class InputDecorationTheme with Diagnosticable {
'Use floatingLabelBehavior instead. '
'This feature was deprecated after v1.13.2.'
)
// ignore: deprecated_member_use_from_same_package
this.hasFloatingPlaceholder = true,
this.floatingLabelBehavior = FloatingLabelBehavior.auto,
this.isDense = false,
Expand All @@ -3648,7 +3638,6 @@ class InputDecorationTheme with Diagnosticable {
assert(isCollapsed != null),
assert(filled != null),
assert(alignLabelWithHint != null),
// ignore: deprecated_member_use_from_same_package
assert(!(!hasFloatingPlaceholder && identical(floatingLabelBehavior, FloatingLabelBehavior.always)),
'hasFloatingPlaceholder=false conflicts with FloatingLabelBehavior.always');

Expand Down Expand Up @@ -4001,7 +3990,6 @@ class InputDecorationTheme with Diagnosticable {
hintStyle: hintStyle ?? this.hintStyle,
errorStyle: errorStyle ?? this.errorStyle,
errorMaxLines: errorMaxLines ?? this.errorMaxLines,
// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: hasFloatingPlaceholder ?? this.hasFloatingPlaceholder,
floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior,
isDense: isDense ?? this.isDense,
Expand Down Expand Up @@ -4033,7 +4021,6 @@ class InputDecorationTheme with Diagnosticable {
hintStyle,
errorStyle,
errorMaxLines,
// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder,
floatingLabelBehavior,
isDense,
Expand Down Expand Up @@ -4100,7 +4087,6 @@ class InputDecorationTheme with Diagnosticable {
properties.add(DiagnosticsProperty<TextStyle>('hintStyle', hintStyle, defaultValue: defaultTheme.hintStyle));
properties.add(DiagnosticsProperty<TextStyle>('errorStyle', errorStyle, defaultValue: defaultTheme.errorStyle));
properties.add(IntProperty('errorMaxLines', errorMaxLines, defaultValue: defaultTheme.errorMaxLines));
// ignore: deprecated_member_use_from_same_package
properties.add(DiagnosticsProperty<bool>('hasFloatingPlaceholder', hasFloatingPlaceholder, defaultValue: defaultTheme.hasFloatingPlaceholder));
properties.add(DiagnosticsProperty<FloatingLabelBehavior>('floatingLabelBehavior', floatingLabelBehavior, defaultValue: defaultTheme.floatingLabelBehavior));
properties.add(DiagnosticsProperty<bool>('isDense', isDense, defaultValue: defaultTheme.isDense));
Expand Down
Expand Up @@ -29,9 +29,9 @@ const double _maxCalendarWidthPortrait = 480.0;

/// Displays a scrollable calendar grid that allows a user to select a range
/// of dates.
///
/// Note: this is not publicly exported (see pickers.dart), as it is an
/// internal component used by [showDateRangePicker].
//
// This is not publicly exported (see pickers.dart), as it is an
// internal component used by [showDateRangePicker].
class CalendarDateRangePicker extends StatefulWidget {
/// Creates a scrollable calendar grid for picking date ranges.
CalendarDateRangePicker({
Expand Down
Expand Up @@ -21,7 +21,7 @@ import '../theme.dart';

import 'date_picker_common.dart';

// NOTE: this is the original implementation for the Material Date Picker.
// This is the original implementation for the Material Date Picker.
// These classes are deprecated and the whole file can be removed after
// this has been on stable for long enough for people to migrate to the new
// CalendarDatePicker (if needed, as showDatePicker has already been migrated
Expand Down Expand Up @@ -406,7 +406,6 @@ class MonthPicker extends StatefulWidget {
_MonthPickerState createState() => _MonthPickerState();
}

// ignore: deprecated_member_use_from_same_package
class _MonthPickerState extends State<MonthPicker> with SingleTickerProviderStateMixin {
static final Animatable<double> _chevronOpacityTween = Tween<double>(begin: 1.0, end: 0.0)
.chain(CurveTween(curve: Curves.easeInOut));
Expand All @@ -428,7 +427,6 @@ class _MonthPickerState extends State<MonthPicker> with SingleTickerProviderStat
}

@override
// ignore: deprecated_member_use_from_same_package
void didUpdateWidget(MonthPicker oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.selectedDate != oldWidget.selectedDate) {
Expand Down Expand Up @@ -479,7 +477,6 @@ class _MonthPickerState extends State<MonthPicker> with SingleTickerProviderStat

Widget _buildItems(BuildContext context, int index) {
final DateTime month = _addMonthsToMonthDate(widget.firstDate, index);
// ignore: deprecated_member_use_from_same_package
return DayPicker(
key: ValueKey<DateTime>(month),
selectedDate: widget.selectedDate,
Expand Down Expand Up @@ -675,7 +672,6 @@ class YearPicker extends StatefulWidget {
_YearPickerState createState() => _YearPickerState();
}

// ignore: deprecated_member_use_from_same_package
class _YearPickerState extends State<YearPicker> {
static const double _itemExtent = 50.0;
ScrollController scrollController;
Expand Down
Expand Up @@ -12,7 +12,7 @@ import '../material.dart';
import '../text_theme.dart';
import '../theme.dart';

// NOTE: This is an internal implementation file. Even though there are public
// This is an internal implementation file. Even though there are public
// classes and functions defined here, they are only meant to be used by the
// date picker implementation and are not exported as part of the Material library.
// See pickers.dart for exactly what is considered part of the public API.
Expand Down
3 changes: 1 addition & 2 deletions packages/flutter/lib/src/material/pickers/date_utils.dart
Expand Up @@ -4,10 +4,9 @@

// @dart = 2.8


// Common date utility functions used by the date picker implementation

// NOTE: This is an internal implementation file. Even though there are public
// This is an internal implementation file. Even though there are public
// classes and functions defined here, they are only meant to be used by the
// date picker implementation and are not exported as part of the Material library.
// See pickers.dart for exactly what is considered part of the public API.
Expand Down

0 comments on commit 4c6971b

Please sign in to comment.