Skip to content

Commit abebd34

Browse files
authored
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.
1 parent 176b439 commit abebd34

File tree

10 files changed

+14
-38
lines changed

10 files changed

+14
-38
lines changed

packages/flutter/lib/src/foundation/diagnostics.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,7 @@ mixin Diagnosticable {
32523252
///
32533253
/// Used by [toDiagnosticsNode] and [toString].
32543254
///
3255-
/// Do not add values, that have lifetime shorter than the object.
3255+
/// Do not add values that have lifetime shorter than the object.
32563256
@protected
32573257
@mustCallSuper
32583258
void debugFillProperties(DiagnosticPropertiesBuilder properties) { }

packages/flutter/lib/src/material/icon_button.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ class IconButton extends StatelessWidget {
795795
@override
796796
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
797797
super.debugFillProperties(properties);
798-
properties.add(DiagnosticsProperty<Widget>('icon', icon, showName: false));
799798
properties.add(StringProperty('tooltip', tooltip, defaultValue: null, quoted: false));
800799
properties.add(ObjectFlagProperty<VoidCallback>('onPressed', onPressed, ifNull: 'disabled'));
801800
properties.add(ColorProperty('color', color, defaultValue: null));

packages/flutter/lib/src/material/list_tile.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,6 @@ class ListTile extends StatelessWidget {
897897
@override
898898
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
899899
super.debugFillProperties(properties);
900-
properties.add(DiagnosticsProperty<Widget>('leading', leading, defaultValue: null));
901-
properties.add(DiagnosticsProperty<Widget>('title', title, defaultValue: null));
902-
properties.add(DiagnosticsProperty<Widget>('subtitle', subtitle, defaultValue: null));
903-
properties.add(DiagnosticsProperty<Widget>('trailing', trailing, defaultValue: null));
904900
properties.add(FlagProperty('isThreeLine', value: isThreeLine, ifTrue:'THREE_LINE', ifFalse: 'TWO_LINE', showName: true, defaultValue: false));
905901
properties.add(FlagProperty('dense', value: dense, ifTrue: 'true', ifFalse: 'false', showName: true));
906902
properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null));

packages/flutter/lib/src/material/menu_anchor.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ class MenuAnchor extends StatefulWidget {
283283
properties.add(DiagnosticsProperty<MenuStyle?>('style', style));
284284
properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior));
285285
properties.add(DiagnosticsProperty<Offset?>('alignmentOffset', alignmentOffset));
286-
properties.add(StringProperty('child', child.toString()));
287286
}
288287
}
289288

@@ -1041,11 +1040,8 @@ class MenuItemButton extends StatefulWidget {
10411040
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
10421041
super.debugFillProperties(properties);
10431042
properties.add(FlagProperty('enabled', value: onPressed != null, ifFalse: 'DISABLED'));
1044-
properties.add(DiagnosticsProperty<String>('child', child.toString()));
10451043
properties.add(DiagnosticsProperty<ButtonStyle?>('style', style, defaultValue: null));
10461044
properties.add(DiagnosticsProperty<MenuSerializableShortcut?>('shortcut', shortcut, defaultValue: null));
1047-
properties.add(DiagnosticsProperty<Widget?>('leadingIcon', leadingIcon, defaultValue: null));
1048-
properties.add(DiagnosticsProperty<Widget?>('trailingIcon', trailingIcon, defaultValue: null));
10491045
properties.add(DiagnosticsProperty<FocusNode?>('focusNode', focusNode, defaultValue: null));
10501046
properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.none));
10511047
properties.add(DiagnosticsProperty<MaterialStatesController?>('statesController', statesController, defaultValue: null));
@@ -1802,9 +1798,6 @@ class SubmenuButton extends StatefulWidget {
18021798
@override
18031799
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
18041800
super.debugFillProperties(properties);
1805-
properties.add(DiagnosticsProperty<Widget>('leadingIcon', leadingIcon, defaultValue: null));
1806-
properties.add(DiagnosticsProperty<String>('child', child.toString()));
1807-
properties.add(DiagnosticsProperty<Widget>('trailingIcon', trailingIcon, defaultValue: null));
18081801
properties.add(DiagnosticsProperty<FocusNode?>('focusNode', focusNode));
18091802
properties.add(DiagnosticsProperty<MenuStyle>('menuStyle', menuStyle, defaultValue: null));
18101803
properties.add(DiagnosticsProperty<Offset>('alignmentOffset', alignmentOffset));
@@ -3140,7 +3133,6 @@ class _MenuItemLabel extends StatelessWidget {
31403133
@override
31413134
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
31423135
super.debugFillProperties(properties);
3143-
properties.add(DiagnosticsProperty<String>('child', child.toString()));
31443136
properties.add(DiagnosticsProperty<MenuSerializableShortcut>('shortcut', shortcut, defaultValue: null));
31453137
properties.add(DiagnosticsProperty<bool>('hasSubmenu', hasSubmenu));
31463138
properties.add(DiagnosticsProperty<bool>('showDecoration', showDecoration));

packages/flutter/lib/src/material/segmented_button_theme.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class SegmentedButtonThemeData with Diagnosticable {
9494
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
9595
super.debugFillProperties(properties);
9696
properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null));
97-
properties.add(DiagnosticsProperty<Widget>('selectedIcon', selectedIcon, defaultValue: null));
9897
}
9998
}
10099

packages/flutter/lib/src/material/tabs.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ class Tab extends StatelessWidget implements PreferredSizeWidget {
191191
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
192192
super.debugFillProperties(properties);
193193
properties.add(StringProperty('text', text, defaultValue: null));
194-
properties.add(DiagnosticsProperty<Widget>('icon', icon, defaultValue: null));
195194
}
196195

197196
@override

packages/flutter/lib/src/widgets/placeholder.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,5 @@ class Placeholder extends StatelessWidget {
111111
properties.add(DoubleProperty('strokeWidth', strokeWidth, defaultValue: 2.0));
112112
properties.add(DoubleProperty('fallbackWidth', fallbackWidth, defaultValue: 400.0));
113113
properties.add(DoubleProperty('fallbackHeight', fallbackHeight, defaultValue: 400.0));
114-
properties.add(DiagnosticsProperty<Widget>('child', child, defaultValue: null));
115114
}
116115
}

packages/flutter/lib/src/widgets/spell_check.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/foundation.dart' show TargetPlatform, defaultTargetPlatform;
5+
import 'package:flutter/foundation.dart';
66
import 'package:flutter/painting.dart';
77
import 'package:flutter/services.dart'
88
show SpellCheckResults, SpellCheckService, SuggestionSpan, TextEditingValue;
99

1010
import 'editable_text.dart' show EditableTextContextMenuBuilder;
11-
import 'framework.dart' show immutable;
1211

1312
/// Controls how spell check is performed for text input.
1413
///
@@ -83,26 +82,24 @@ class SpellCheckConfiguration {
8382

8483
@override
8584
String toString() {
86-
return '''
87-
spell check enabled : $_spellCheckEnabled
88-
spell check service : $spellCheckService
89-
misspelled text style : $misspelledTextStyle
90-
spell check suggestions toolbar builder: $spellCheckSuggestionsToolbarBuilder
91-
'''
92-
.trim();
85+
return '${objectRuntimeType(this, 'SpellCheckConfiguration')}('
86+
'${_spellCheckEnabled ? 'enabled' : 'disabled'}, '
87+
'service: $spellCheckService, '
88+
'text style: $misspelledTextStyle, '
89+
'toolbar builder: $spellCheckSuggestionsToolbarBuilder'
90+
')';
9391
}
9492

9593
@override
9694
bool operator ==(Object other) {
97-
if (identical(this, other)) {
98-
return true;
95+
if (other.runtimeType != runtimeType) {
96+
return false;
9997
}
100-
10198
return other is SpellCheckConfiguration
102-
&& other.spellCheckService == spellCheckService
103-
&& other.misspelledTextStyle == misspelledTextStyle
104-
&& other.spellCheckSuggestionsToolbarBuilder == spellCheckSuggestionsToolbarBuilder
105-
&& other._spellCheckEnabled == _spellCheckEnabled;
99+
&& other.spellCheckService == spellCheckService
100+
&& other.misspelledTextStyle == misspelledTextStyle
101+
&& other.spellCheckSuggestionsToolbarBuilder == spellCheckSuggestionsToolbarBuilder
102+
&& other._spellCheckEnabled == _spellCheckEnabled;
106103
}
107104

108105
@override

packages/flutter/test/material/list_tile_test.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,10 +2016,6 @@ void main() {
20162016
expect(
20172017
description,
20182018
equalsIgnoringHashCodes(<String>[
2019-
'leading: Text',
2020-
'title: Text',
2021-
'subtitle: Text',
2022-
'trailing: Text',
20232019
'isThreeLine: THREE_LINE',
20242020
'dense: true',
20252021
'visualDensity: VisualDensity#00000(h: 0.0, v: 0.0)',

packages/flutter/test/material/menu_anchor_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,6 @@ void main() {
23562356
description,
23572357
equalsIgnoringHashCodes(
23582358
<String>[
2359-
'child: Text("Menu 0")',
23602359
'focusNode: null',
23612360
'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)))',
23622361
'alignmentOffset: null',

0 commit comments

Comments
 (0)