From abebd340d7f3d36179c02eb2e65413552f349314 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 30 Jan 2024 14:41:15 -0800 Subject: [PATCH] Style correctness improvements for toStrings and related fixes (#142485) Children should be omitted from debugFillProperties (if they really need to be included they should be in debugDescribeChildren, but in general for widgets we don't bother including them since they are eventually included anyway). toStrings should not contain newlines (or, ideally, should use Diagnosticable). Also some minor tweaks to match grammar and style guide conventions. --- .../lib/src/foundation/diagnostics.dart | 2 +- .../flutter/lib/src/material/icon_button.dart | 1 - .../flutter/lib/src/material/list_tile.dart | 4 --- .../flutter/lib/src/material/menu_anchor.dart | 8 ----- .../src/material/segmented_button_theme.dart | 1 - packages/flutter/lib/src/material/tabs.dart | 1 - .../flutter/lib/src/widgets/placeholder.dart | 1 - .../flutter/lib/src/widgets/spell_check.dart | 29 +++++++++---------- .../flutter/test/material/list_tile_test.dart | 4 --- .../test/material/menu_anchor_test.dart | 1 - 10 files changed, 14 insertions(+), 38 deletions(-) diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index d56ba92592..70f0cf9429 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart @@ -3252,7 +3252,7 @@ mixin Diagnosticable { /// /// Used by [toDiagnosticsNode] and [toString]. /// - /// Do not add values, that have lifetime shorter than the object. + /// Do not add values that have lifetime shorter than the object. @protected @mustCallSuper void debugFillProperties(DiagnosticPropertiesBuilder properties) { } diff --git a/packages/flutter/lib/src/material/icon_button.dart b/packages/flutter/lib/src/material/icon_button.dart index 6eac56d2b2..74b64b10be 100644 --- a/packages/flutter/lib/src/material/icon_button.dart +++ b/packages/flutter/lib/src/material/icon_button.dart @@ -795,7 +795,6 @@ class IconButton extends StatelessWidget { @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add(DiagnosticsProperty('icon', icon, showName: false)); properties.add(StringProperty('tooltip', tooltip, defaultValue: null, quoted: false)); properties.add(ObjectFlagProperty('onPressed', onPressed, ifNull: 'disabled')); properties.add(ColorProperty('color', color, defaultValue: null)); diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 98d1215159..877737de59 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -897,10 +897,6 @@ class ListTile extends StatelessWidget { @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add(DiagnosticsProperty('leading', leading, defaultValue: null)); - properties.add(DiagnosticsProperty('title', title, defaultValue: null)); - properties.add(DiagnosticsProperty('subtitle', subtitle, defaultValue: null)); - properties.add(DiagnosticsProperty('trailing', trailing, defaultValue: null)); properties.add(FlagProperty('isThreeLine', value: isThreeLine, ifTrue:'THREE_LINE', ifFalse: 'TWO_LINE', showName: true, defaultValue: false)); properties.add(FlagProperty('dense', value: dense, ifTrue: 'true', ifFalse: 'false', showName: true)); properties.add(DiagnosticsProperty('visualDensity', visualDensity, defaultValue: null)); diff --git a/packages/flutter/lib/src/material/menu_anchor.dart b/packages/flutter/lib/src/material/menu_anchor.dart index 45c292259b..451da7ca10 100644 --- a/packages/flutter/lib/src/material/menu_anchor.dart +++ b/packages/flutter/lib/src/material/menu_anchor.dart @@ -283,7 +283,6 @@ class MenuAnchor extends StatefulWidget { properties.add(DiagnosticsProperty('style', style)); properties.add(EnumProperty('clipBehavior', clipBehavior)); properties.add(DiagnosticsProperty('alignmentOffset', alignmentOffset)); - properties.add(StringProperty('child', child.toString())); } } @@ -1041,11 +1040,8 @@ class MenuItemButton extends StatefulWidget { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(FlagProperty('enabled', value: onPressed != null, ifFalse: 'DISABLED')); - properties.add(DiagnosticsProperty('child', child.toString())); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); properties.add(DiagnosticsProperty('shortcut', shortcut, defaultValue: null)); - properties.add(DiagnosticsProperty('leadingIcon', leadingIcon, defaultValue: null)); - properties.add(DiagnosticsProperty('trailingIcon', trailingIcon, defaultValue: null)); properties.add(DiagnosticsProperty('focusNode', focusNode, defaultValue: null)); properties.add(EnumProperty('clipBehavior', clipBehavior, defaultValue: Clip.none)); properties.add(DiagnosticsProperty('statesController', statesController, defaultValue: null)); @@ -1802,9 +1798,6 @@ class SubmenuButton extends StatefulWidget { @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add(DiagnosticsProperty('leadingIcon', leadingIcon, defaultValue: null)); - properties.add(DiagnosticsProperty('child', child.toString())); - properties.add(DiagnosticsProperty('trailingIcon', trailingIcon, defaultValue: null)); properties.add(DiagnosticsProperty('focusNode', focusNode)); properties.add(DiagnosticsProperty('menuStyle', menuStyle, defaultValue: null)); properties.add(DiagnosticsProperty('alignmentOffset', alignmentOffset)); @@ -3140,7 +3133,6 @@ class _MenuItemLabel extends StatelessWidget { @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add(DiagnosticsProperty('child', child.toString())); properties.add(DiagnosticsProperty('shortcut', shortcut, defaultValue: null)); properties.add(DiagnosticsProperty('hasSubmenu', hasSubmenu)); properties.add(DiagnosticsProperty('showDecoration', showDecoration)); diff --git a/packages/flutter/lib/src/material/segmented_button_theme.dart b/packages/flutter/lib/src/material/segmented_button_theme.dart index 4f302b15c3..b14a83a794 100644 --- a/packages/flutter/lib/src/material/segmented_button_theme.dart +++ b/packages/flutter/lib/src/material/segmented_button_theme.dart @@ -94,7 +94,6 @@ class SegmentedButtonThemeData with Diagnosticable { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); - properties.add(DiagnosticsProperty('selectedIcon', selectedIcon, defaultValue: null)); } } diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index ee2d40f3c1..50ec52a285 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -191,7 +191,6 @@ class Tab extends StatelessWidget implements PreferredSizeWidget { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(StringProperty('text', text, defaultValue: null)); - properties.add(DiagnosticsProperty('icon', icon, defaultValue: null)); } @override diff --git a/packages/flutter/lib/src/widgets/placeholder.dart b/packages/flutter/lib/src/widgets/placeholder.dart index 9be0303421..1fdd6e7e27 100644 --- a/packages/flutter/lib/src/widgets/placeholder.dart +++ b/packages/flutter/lib/src/widgets/placeholder.dart @@ -111,6 +111,5 @@ class Placeholder extends StatelessWidget { properties.add(DoubleProperty('strokeWidth', strokeWidth, defaultValue: 2.0)); properties.add(DoubleProperty('fallbackWidth', fallbackWidth, defaultValue: 400.0)); properties.add(DoubleProperty('fallbackHeight', fallbackHeight, defaultValue: 400.0)); - properties.add(DiagnosticsProperty('child', child, defaultValue: null)); } } diff --git a/packages/flutter/lib/src/widgets/spell_check.dart b/packages/flutter/lib/src/widgets/spell_check.dart index 717fddeaab..391ec2b707 100644 --- a/packages/flutter/lib/src/widgets/spell_check.dart +++ b/packages/flutter/lib/src/widgets/spell_check.dart @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart' show TargetPlatform, defaultTargetPlatform; +import 'package:flutter/foundation.dart'; import 'package:flutter/painting.dart'; import 'package:flutter/services.dart' show SpellCheckResults, SpellCheckService, SuggestionSpan, TextEditingValue; import 'editable_text.dart' show EditableTextContextMenuBuilder; -import 'framework.dart' show immutable; /// Controls how spell check is performed for text input. /// @@ -83,26 +82,24 @@ class SpellCheckConfiguration { @override String toString() { - return ''' - spell check enabled : $_spellCheckEnabled - spell check service : $spellCheckService - misspelled text style : $misspelledTextStyle - spell check suggestions toolbar builder: $spellCheckSuggestionsToolbarBuilder -''' - .trim(); + return '${objectRuntimeType(this, 'SpellCheckConfiguration')}(' + '${_spellCheckEnabled ? 'enabled' : 'disabled'}, ' + 'service: $spellCheckService, ' + 'text style: $misspelledTextStyle, ' + 'toolbar builder: $spellCheckSuggestionsToolbarBuilder' + ')'; } @override bool operator ==(Object other) { - if (identical(this, other)) { - return true; + if (other.runtimeType != runtimeType) { + return false; } - return other is SpellCheckConfiguration - && other.spellCheckService == spellCheckService - && other.misspelledTextStyle == misspelledTextStyle - && other.spellCheckSuggestionsToolbarBuilder == spellCheckSuggestionsToolbarBuilder - && other._spellCheckEnabled == _spellCheckEnabled; + && other.spellCheckService == spellCheckService + && other.misspelledTextStyle == misspelledTextStyle + && other.spellCheckSuggestionsToolbarBuilder == spellCheckSuggestionsToolbarBuilder + && other._spellCheckEnabled == _spellCheckEnabled; } @override diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index e0fbb7ba5c..5e7dd85934 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -2016,10 +2016,6 @@ void main() { expect( description, equalsIgnoringHashCodes([ - 'leading: Text', - 'title: Text', - 'subtitle: Text', - 'trailing: Text', 'isThreeLine: THREE_LINE', 'dense: true', 'visualDensity: VisualDensity#00000(h: 0.0, v: 0.0)', diff --git a/packages/flutter/test/material/menu_anchor_test.dart b/packages/flutter/test/material/menu_anchor_test.dart index f722879c8a..a9fce196a6 100644 --- a/packages/flutter/test/material/menu_anchor_test.dart +++ b/packages/flutter/test/material/menu_anchor_test.dart @@ -2356,7 +2356,6 @@ void main() { description, equalsIgnoringHashCodes( [ - 'child: Text("Menu 0")', 'focusNode: null', 'menuStyle: MenuStyle#00000(backgroundColor: MaterialStatePropertyAll(MaterialColor(primary value: Color(0xff4caf50))), elevation: MaterialStatePropertyAll(20.0), shape: MaterialStatePropertyAll(RoundedRectangleBorder(BorderSide(width: 0.0, style: none), BorderRadius.zero)))', 'alignmentOffset: null',