diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index 099e218ec6b..d54aadc7534 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart @@ -2607,7 +2607,7 @@ class _PlatformTextInputControl with TextInputControl { /// * [SystemContextMenu], which wraps this functionality in a widget. /// * [MediaQuery.maybeSupportsShowingSystemContextMenu], which indicates /// whether the system context menu is supported. -class SystemContextMenuController with SystemContextMenuClient { +class SystemContextMenuController with SystemContextMenuClient, Diagnosticable { /// Creates an instance of [SystemContextMenuController]. /// /// Not shown until [show] is called. @@ -2819,8 +2819,20 @@ class SystemContextMenuController with SystemContextMenuClient { } @override - String toString() { - return 'SystemContextMenuController(onSystemHide=$onSystemHide, _hiddenBySystem=$_hiddenBySystem, _isVisible=$isVisible, _isDisposed=$_isDisposed)'; + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('isVisible', isVisible)); + properties.add( + FlagProperty( + 'onSystemHide', + value: onSystemHide != null, + ifTrue: 'callback set', + ifFalse: 'callback null', + showName: true, + ), + ); + properties.add(DiagnosticsProperty('_hiddenBySystem', _hiddenBySystem)); + properties.add(DiagnosticsProperty('_isDisposed', _isDisposed)); } /// Used to release resources when this instance will never be used again. @@ -2967,7 +2979,8 @@ final class IOSSystemContextMenuItemDataSelectAll extends IOSSystemContextMenuIt /// * [IOSSystemContextMenuItemLookUp], which performs a similar role but at the /// widget level, where the title can be replaced with a default localized /// value. -final class IOSSystemContextMenuItemDataLookUp extends IOSSystemContextMenuItemData { +final class IOSSystemContextMenuItemDataLookUp extends IOSSystemContextMenuItemData + with Diagnosticable { /// Creates an instance of [IOSSystemContextMenuItemDataLookUp]. const IOSSystemContextMenuItemDataLookUp({required this.title}); @@ -2978,8 +2991,9 @@ final class IOSSystemContextMenuItemDataLookUp extends IOSSystemContextMenuItemD String get _jsonType => 'lookUp'; @override - String toString() { - return 'IOSSystemContextMenuItemDataLookUp(title: $title)'; + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('title', title)); } } @@ -2998,7 +3012,8 @@ final class IOSSystemContextMenuItemDataLookUp extends IOSSystemContextMenuItemD /// * [IOSSystemContextMenuItemSearchWeb], which performs a similar role but at /// the widget level, where the title can be replaced with a default localized /// value. -final class IOSSystemContextMenuItemDataSearchWeb extends IOSSystemContextMenuItemData { +final class IOSSystemContextMenuItemDataSearchWeb extends IOSSystemContextMenuItemData + with Diagnosticable { /// Creates an instance of [IOSSystemContextMenuItemDataSearchWeb]. const IOSSystemContextMenuItemDataSearchWeb({required this.title}); @@ -3009,8 +3024,9 @@ final class IOSSystemContextMenuItemDataSearchWeb extends IOSSystemContextMenuIt String get _jsonType => 'searchWeb'; @override - String toString() { - return 'IOSSystemContextMenuItemDataSearchWeb(title: $title)'; + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('title', title)); } } @@ -3028,7 +3044,8 @@ final class IOSSystemContextMenuItemDataSearchWeb extends IOSSystemContextMenuIt /// * [IOSSystemContextMenuItemShare], which performs a similar role but at /// the widget level, where the title can be replaced with a default /// localized value. -final class IOSSystemContextMenuItemDataShare extends IOSSystemContextMenuItemData { +final class IOSSystemContextMenuItemDataShare extends IOSSystemContextMenuItemData + with Diagnosticable { /// Creates an instance of [IOSSystemContextMenuItemDataShare]. const IOSSystemContextMenuItemDataShare({required this.title}); @@ -3039,8 +3056,9 @@ final class IOSSystemContextMenuItemDataShare extends IOSSystemContextMenuItemDa String get _jsonType => 'share'; @override - String toString() { - return 'IOSSystemContextMenuItemDataShare(title: $title)'; + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('title', title)); } } diff --git a/packages/flutter/test/services/text_input_test.dart b/packages/flutter/test/services/text_input_test.dart index f7377ee3f00..ea9b3b77121 100644 --- a/packages/flutter/test/services/text_input_test.dart +++ b/packages/flutter/test/services/text_input_test.dart @@ -1445,6 +1445,51 @@ void main() { expect(client.latestMethodCall, 'didChangeInputControl'); }); }); + + test('SystemContextMenuController debugFillProperties', () { + final SystemContextMenuController controller = SystemContextMenuController(onSystemHide: () {}); + final List diagnosticsNodes = controller.toDiagnosticsNode().getProperties(); + expect(diagnosticsNodes, hasLength(4)); + expect(diagnosticsNodes[0].name, 'isVisible'); + expect(diagnosticsNodes[0].value, false); + expect(diagnosticsNodes[1].name, 'onSystemHide'); + expect(diagnosticsNodes[1].value, true); + expect(diagnosticsNodes[2].name, '_hiddenBySystem'); + expect(diagnosticsNodes[2].value, false); + expect(diagnosticsNodes[3].name, '_isDisposed'); + expect(diagnosticsNodes[3].value, false); + }); + + test('IOSSystemContextMenuItemDataLookUp debugFillProperties', () { + const String title = 'my title'; + const IOSSystemContextMenuItemDataLookUp item = IOSSystemContextMenuItemDataLookUp( + title: title, + ); + final List diagnosticsNodes = item.toDiagnosticsNode().getProperties(); + expect(diagnosticsNodes, hasLength(1)); + expect(diagnosticsNodes.first.name, 'title'); + expect(diagnosticsNodes.first.value, title); + }); + + test('IOSSystemContextMenuItemDataSearchWeb debugFillProperties', () { + const String title = 'my title'; + const IOSSystemContextMenuItemDataSearchWeb item = IOSSystemContextMenuItemDataSearchWeb( + title: title, + ); + final List diagnosticsNodes = item.toDiagnosticsNode().getProperties(); + expect(diagnosticsNodes, hasLength(1)); + expect(diagnosticsNodes.first.name, 'title'); + expect(diagnosticsNodes.first.value, title); + }); + + test('IOSSystemContextMenuItemDataShare debugFillProperties', () { + const String title = 'my title'; + const IOSSystemContextMenuItemDataShare item = IOSSystemContextMenuItemDataShare(title: title); + final List diagnosticsNodes = item.toDiagnosticsNode().getProperties(); + expect(diagnosticsNodes, hasLength(1)); + expect(diagnosticsNodes.first.name, 'title'); + expect(diagnosticsNodes.first.value, title); + }); } class FakeTextInputClient with TextInputClient {