diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 623ce0fc5d..3dd20a0d27 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -880,6 +880,7 @@ class _CupertinoTextFieldState extends State with Restoratio _createLocalController(); } _effectiveFocusNode.canRequestFocus = widget.enabled ?? true; + _effectiveFocusNode.addListener(_handleFocusChanged); } @override diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 07bf6f279d..a74039fe0d 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -284,6 +284,36 @@ void main() { skip: kIsWeb, // [intended] the web handles this on its own. ); + testWidgets('can get text selection color initially on desktop', (WidgetTester tester) async { + final FocusNode focusNode = FocusNode(); + final TextEditingController controller = TextEditingController( + text: 'blah1 blah2', + ); + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: RepaintBoundary( + child: CupertinoTextField( + key: const ValueKey(1), + controller: controller, + focusNode: focusNode, + ), + ), + ), + ), + ); + + controller.selection = const TextSelection(baseOffset: 0, extentOffset: 11); + focusNode.requestFocus(); + await tester.pump(); + + expect(focusNode.hasFocus, true); + await expectLater( + find.byKey(const ValueKey(1)), + matchesGoldenFile('text_field_golden.text_selection_color.0.png'), + ); + }); + testWidgets('Activates the text field when receives semantics focus on Mac', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner!;