From 64f7bf7e2ffd1f56c3185f344ee8bc07aad0e094 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Thu, 7 Apr 2022 22:25:50 +0300 Subject: [PATCH] Add ListTile debugFillProperties (#100765) --- .../flutter/lib/src/material/list_tile.dart | 33 +++++++++ .../flutter/test/material/list_tile_test.dart | 72 +++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 21bd23e8e2..5ba7d827c1 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -798,6 +798,39 @@ 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)); + properties.add(DiagnosticsProperty('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null)); + properties.add(ColorProperty('iconColor', iconColor, defaultValue: null)); + properties.add(ColorProperty('textColor', textColor, defaultValue: null)); + properties.add(DiagnosticsProperty('contentPadding', contentPadding, defaultValue: null)); + properties.add(FlagProperty('enabled', value: enabled, ifTrue: 'true', ifFalse: 'false', showName: true, defaultValue: true)); + properties.add(DiagnosticsProperty('onTap', onTap, defaultValue: null)); + properties.add(DiagnosticsProperty('onLongPress', onLongPress, defaultValue: null)); + properties.add(DiagnosticsProperty('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(FlagProperty('selected', value: selected, ifTrue: 'true', ifFalse: 'false', showName: true, defaultValue: false)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(DiagnosticsProperty('focusNode', focusNode, defaultValue: null)); + properties.add(FlagProperty('autofocus', value: autofocus, ifTrue: 'true', ifFalse: 'false', showName: true, defaultValue: false)); + properties.add(ColorProperty('tileColor', tileColor, defaultValue: null)); + properties.add(ColorProperty('selectedTileColor', selectedTileColor, defaultValue: null)); + properties.add(FlagProperty('enableFeedback', value: enableFeedback, ifTrue: 'true', ifFalse: 'false', showName: true)); + properties.add(DoubleProperty('horizontalTitleGap', horizontalTitleGap, defaultValue: null)); + properties.add(DoubleProperty('minVerticalPadding', minVerticalPadding, defaultValue: null)); + properties.add(DoubleProperty('minLeadingWidth', minLeadingWidth, defaultValue: null)); + } } // Identifies the children of a _ListTileElement. diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index ab6f576a1c..a37e8a2b63 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -2228,6 +2228,78 @@ void main() { trailing = _getTextRenderObject(tester, 'trailing'); expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color); }); + + testWidgets('Default ListTile debugFillProperties', (WidgetTester tester) async { + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + const ListTile().debugFillProperties(builder); + + final List description = builder.properties + .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) + .map((DiagnosticsNode node) => node.toString()) + .toList(); + + expect(description, []); + }); + + testWidgets('ListTile implements debugFillProperties', (WidgetTester tester) async { + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + const ListTile( + leading: Text('leading'), + title: Text('title'), + subtitle: Text('trailing'), + trailing: Text('trailing'), + isThreeLine: true, + dense: true, + visualDensity: VisualDensity.standard, + shape: RoundedRectangleBorder(), + style: ListTileStyle.list, + selectedColor: Color(0xff0000ff), + iconColor: Color(0xff00ff00), + textColor: Color(0xffff0000), + contentPadding: EdgeInsets.zero, + enabled: false, + selected: true, + focusColor: Color(0xff00ffff), + hoverColor: Color(0xff0000ff), + autofocus: true, + tileColor: Color(0xffffff00), + selectedTileColor: Color(0xff123456), + enableFeedback: false, + horizontalTitleGap: 4.0, + minVerticalPadding: 2.0, + minLeadingWidth: 6.0, + ).debugFillProperties(builder); + + final List description = builder.properties + .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) + .map((DiagnosticsNode node) => node.toString()) + .toList(); + + expect(description[0], 'leading: Text'); + expect(description[1], 'title: Text'); + expect(description[2], 'subtitle: Text'); + expect(description[3], 'trailing: Text'); + expect(description[4], 'isThreeLine: THREE_LINE'); + expect(description[5], 'dense: true'); + expect(description[6], equalsIgnoringHashCodes('visualDensity: VisualDensity#00000(h: 0.0, v: 0.0)')); + expect(description[7], 'shape: RoundedRectangleBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none), BorderRadius.zero)'); + expect(description[8], 'style: ListTileStyle.list'); + expect(description[9], 'selectedColor: Color(0xff0000ff)'); + expect(description[10], 'iconColor: Color(0xff00ff00)'); + expect(description[11], 'textColor: Color(0xffff0000)'); + expect(description[12], 'contentPadding: EdgeInsets.zero'); + expect(description[13], 'enabled: false'); + expect(description[14], 'selected: true'); + expect(description[15], 'focusColor: Color(0xff00ffff)'); + expect(description[16], 'hoverColor: Color(0xff0000ff)'); + expect(description[17], 'autofocus: true'); + expect(description[18], 'tileColor: Color(0xffffff00)'); + expect(description[19], 'selectedTileColor: Color(0xff123456)'); + expect(description[20], 'enableFeedback: false'); + expect(description[21], 'horizontalTitleGap: 4.0'); + expect(description[22], 'minVerticalPadding: 2.0'); + expect(description[23], 'minLeadingWidth: 6.0'); + }); } RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {