From 7c0e7b91c01a2e6238f76bd8abdf91231690c13d Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Fri, 17 Jul 2026 09:54:24 +0200 Subject: [PATCH 1/5] fix material_ui cross imports in cupertino_ui samples --- .../lib/list_tile/cupertino_list_tile.0.dart | 20 ++++++---------- packages/cupertino_ui/example/pubspec.yaml | 1 + .../cupertino_context_menu.0_test.dart | 5 ++-- .../cupertino_context_menu.1_test.dart | 5 ++-- .../list_tile/cupertino_list_tile.0_test.dart | 23 +++++-------------- 5 files changed, 18 insertions(+), 36 deletions(-) diff --git a/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart b/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart index eb0750eebb52..e44653df5c0d 100644 --- a/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart +++ b/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart @@ -4,7 +4,6 @@ // #region body import 'package:cupertino_ui/cupertino_ui.dart'; -import 'package:material_ui/material_ui.dart'; /// Flutter code sample for [CupertinoListTile]. @@ -25,37 +24,32 @@ class CupertinoListTileExample extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoPageScaffold( - navigationBar: const CupertinoNavigationBar( - middle: Text('CupertinoListTile Sample'), - ), + navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoListTile Sample')), child: ListView( children: const [ CupertinoListTile(title: Text('One-line CupertinoListTile')), - CupertinoListTile( - leading: FlutterLogo(), - title: Text('One-line with leading widget'), - ), + CupertinoListTile(leading: FlutterLogo(), title: Text('One-line with leading widget')), CupertinoListTile( title: Text('One-line with trailing widget'), - trailing: Icon(Icons.more_vert), + trailing: Icon(CupertinoIcons.ellipsis_vertical), ), CupertinoListTile( leading: FlutterLogo(), title: Text('One-line with both widgets'), - trailing: Icon(Icons.more_vert), + trailing: Icon(CupertinoIcons.ellipsis_vertical), ), CupertinoListTile( leading: FlutterLogo(size: 56.0), title: Text('Two-line CupertinoListTile'), subtitle: Text('Here is a subtitle'), - trailing: Icon(Icons.more_vert), - additionalInfo: Icon(Icons.info), + trailing: Icon(CupertinoIcons.ellipsis_vertical), + additionalInfo: Icon(CupertinoIcons.info), ), CupertinoListTile( key: Key('CupertinoListTile with background color'), leading: FlutterLogo(size: 56.0), title: Text('CupertinoListTile with background color'), - backgroundColor: Colors.lightBlue, + backgroundColor: Color(0xFF0000FF), ), ], ), diff --git a/packages/cupertino_ui/example/pubspec.yaml b/packages/cupertino_ui/example/pubspec.yaml index b7180111a604..cf5568bf64ef 100644 --- a/packages/cupertino_ui/example/pubspec.yaml +++ b/packages/cupertino_ui/example/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: test: ^1.31.0 vector_math: ^2.2.0 web: ^1.1.1 + cupertino_icons: ^1.0.9 cupertino_ui: path: .. material_ui: diff --git a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart index b9cabb374d1a..b6b104e475b2 100644 --- a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart +++ b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:material_ui/material_ui.dart'; -import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.0.dart' - as example; +import 'package:cupertino_ui/cupertino_ui.dart'; +import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.0.dart' as example; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart index 2f7ca50494e0..1498fff89a72 100644 --- a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart +++ b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:material_ui/material_ui.dart'; -import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.1.dart' - as example; +import 'package:cupertino_ui/cupertino_ui.dart'; +import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.1.dart' as example; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart b/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart index 61a00c54a6de..95e536237f57 100644 --- a/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart +++ b/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart @@ -3,15 +3,11 @@ // found in the LICENSE file. import 'package:cupertino_ui/cupertino_ui.dart'; -import 'package:material_ui/material_ui.dart'; -import 'package:cupertino_ui_examples/list_tile/cupertino_list_tile.0.dart' - as example; +import 'package:cupertino_ui_examples/list_tile/cupertino_list_tile.0.dart' as example; import 'package:flutter_test/flutter_test.dart'; void main() { - testWidgets('CupertinoListTile respects properties', ( - WidgetTester tester, - ) async { + testWidgets('CupertinoListTile respects properties', (WidgetTester tester) async { await tester.pumpWidget(const example.CupertinoListTileApp()); expect(find.text('CupertinoListTile Sample'), findsOne); @@ -26,17 +22,10 @@ void main() { expect(find.text('Two-line CupertinoListTile'), findsOne); expect(find.text('Here is a subtitle'), findsOne); expect(find.text('CupertinoListTile with background color'), findsOne); - expect(find.byIcon(Icons.more_vert), findsNWidgets(3)); - expect(find.byIcon(Icons.info), findsOne); + expect(find.byIcon(CupertinoIcons.ellipsis_vertical), findsNWidgets(3)); + expect(find.byIcon(CupertinoIcons.info), findsOne); - final Finder tileWithBackgroundFinder = find.byKey( - const Key('CupertinoListTile with background color'), - ); - expect( - tester - .firstWidget(tileWithBackgroundFinder) - .backgroundColor, - Colors.lightBlue, - ); + final Finder tileWithBackgroundFinder = find.byKey(const Key('CupertinoListTile with background color')); + expect(tester.firstWidget(tileWithBackgroundFinder).backgroundColor, const Color(0xFF0000FF)); }); } From 93f470a0e609bd078d31779c0601735fa7533841 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Fri, 17 Jul 2026 10:01:37 +0200 Subject: [PATCH 2/5] update changelog --- packages/cupertino_ui/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cupertino_ui/CHANGELOG.md b/packages/cupertino_ui/CHANGELOG.md index 23017e9f58e6..b0a5004b6e6d 100644 --- a/packages/cupertino_ui/CHANGELOG.md +++ b/packages/cupertino_ui/CHANGELOG.md @@ -1,6 +1,7 @@ ## NEXT * Updates minimum supported SDK version to Flutter 3.38/Dart 3.10. +* Fixes cross imports of `material_ui` in the `cupertino_ui` API examples. ## 0.0.1 From 4fcedb9958fef1bd1775fc6fddd730e735229ec7 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Fri, 17 Jul 2026 10:22:49 +0200 Subject: [PATCH 3/5] fix cross import in text magnifier sample --- .../lib/magnifier/text_magnifier.0.dart | 44 ++++++++++-------- .../test/magnifier/text_magnifier.0_test.dart | 46 +++++-------------- 2 files changed, 37 insertions(+), 53 deletions(-) diff --git a/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart b/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart index d79d27f161fa..d858481d0487 100644 --- a/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart +++ b/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart @@ -4,43 +4,51 @@ // #region body import 'package:flutter/foundation.dart'; -import 'package:material_ui/material_ui.dart'; +import 'package:cupertino_ui/cupertino_ui.dart'; void main() => runApp(const TextMagnifierExampleApp(text: 'Hello world!')); -class TextMagnifierExampleApp extends StatelessWidget { - const TextMagnifierExampleApp({ - super.key, - this.textDirection = TextDirection.ltr, - required this.text, - }); +class TextMagnifierExampleApp extends StatefulWidget { + const TextMagnifierExampleApp({super.key, this.textDirection = TextDirection.ltr, required this.text}); final TextDirection textDirection; final String text; + @override + State createState() => _TextMagnifierExampleAppState(); +} + +class _TextMagnifierExampleAppState extends State { + late final controller = TextEditingController(text: widget.text); + @override Widget build(BuildContext context) { - return MaterialApp( - home: Scaffold( - body: Padding( + return CupertinoApp( + home: CupertinoPageScaffold( + child: Padding( padding: const .symmetric(horizontal: 48.0), child: Center( - child: TextField( - textDirection: textDirection, + child: CupertinoTextField( + textDirection: widget.textDirection, // Create a custom magnifier configuration that // this `TextField` will use to build a magnifier with. magnifierConfiguration: TextMagnifierConfiguration( - magnifierBuilder: - (_, _, ValueNotifier magnifierInfo) => - CustomMagnifier(magnifierInfo: magnifierInfo), + magnifierBuilder: (_, _, ValueNotifier magnifierInfo) => + CustomMagnifier(magnifierInfo: magnifierInfo), ), - controller: TextEditingController(text: text), + controller: controller, ), ), ), ), ); } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } } class CustomMagnifier extends StatelessWidget { @@ -95,9 +103,7 @@ class CustomMagnifier extends StatelessWidget { focalPointOffset: Offset(0, magnifierSize.height / 2), // Decorate it however we'd like! decoration: const MagnifierDecoration( - shape: StarBorder( - side: BorderSide(color: Colors.green, width: 2), - ), + shape: StarBorder(side: BorderSide(color: Color(0xFF00FF00), width: 2)), ), size: magnifierSize, ), diff --git a/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart b/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart index 8d9ee9455936..8806586e1882 100644 --- a/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart +++ b/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart @@ -3,43 +3,30 @@ // found in the LICENSE file. import 'package:flutter/rendering.dart'; -import 'package:material_ui/material_ui.dart'; -import 'package:cupertino_ui_examples/magnifier/text_magnifier.0.dart' - as example; +import 'package:cupertino_ui/cupertino_ui.dart'; +import 'package:cupertino_ui_examples/magnifier/text_magnifier.0.dart' as example; import 'package:flutter_test/flutter_test.dart'; -List _globalize( - Iterable points, - RenderBox box, -) { +List _globalize(Iterable points, RenderBox box) { return points.map((TextSelectionPoint point) { return TextSelectionPoint(box.localToGlobal(point.point), point.direction); }).toList(); } -RenderEditable _findRenderEditable>( - WidgetTester tester, -) { - return (tester.state(find.byType(TextField)) - as TextSelectionGestureDetectorBuilderDelegate) +RenderEditable _findRenderEditable>(WidgetTester tester) { + return (tester.state(find.byType(CupertinoTextField)) as TextSelectionGestureDetectorBuilderDelegate) .editableTextKey .currentState! .renderEditable; } -Offset _textOffsetToPosition>( - WidgetTester tester, - int offset, -) { +Offset _textOffsetToPosition>(WidgetTester tester, int offset) { final RenderEditable renderEditable = _findRenderEditable(tester); final List endpoints = renderEditable .getEndpointsForSelection(TextSelection.collapsed(offset: offset)) .map( - (TextSelectionPoint point) => TextSelectionPoint( - renderEditable.localToGlobal(point.point), - point.direction, - ), + (TextSelectionPoint point) => TextSelectionPoint(renderEditable.localToGlobal(point.point), point.direction), ) .toList(); @@ -65,7 +52,7 @@ void main() { await tester.pumpAndSettle(); final TextEditingController controller = tester - .firstWidget(find.byType(TextField)) + .firstWidget(find.byType(CupertinoTextField)) .controller!; final TextSelection selection = controller.selection; @@ -86,32 +73,23 @@ void main() { testWidgets( 'should show custom magnifier on drag', (WidgetTester tester) async { - await tester.pumpWidget( - const example.TextMagnifierExampleApp(text: defaultText), - ); + await tester.pumpWidget(const example.TextMagnifierExampleApp(text: defaultText)); await showMagnifier(tester, defaultText.indexOf('e')); expect(find.byType(example.CustomMagnifier), findsOneWidget); - await expectLater( - find.byType(example.TextMagnifierExampleApp), - matchesGoldenFile('text_magnifier.0_test.png'), - ); + await expectLater(find.byType(example.TextMagnifierExampleApp), matchesGoldenFile('text_magnifier.0_test.png')); }, variant: const TargetPlatformVariant({.iOS, .android}), // This image is flaky. https://github.com/flutter/flutter/issues/144350 skip: true, ); - testWidgets('should show custom magnifier in RTL', ( - WidgetTester tester, - ) async { + testWidgets('should show custom magnifier in RTL', (WidgetTester tester) async { const String text = 'أثارت زر'; const String textToTapOn = 'ت'; - await tester.pumpWidget( - const example.TextMagnifierExampleApp(textDirection: .rtl, text: text), - ); + await tester.pumpWidget(const example.TextMagnifierExampleApp(textDirection: .rtl, text: text)); await showMagnifier(tester, text.indexOf(textToTapOn)); From 03795d7d673a97c3efef184eb3766757c77c5925 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Fri, 17 Jul 2026 11:55:48 +0200 Subject: [PATCH 4/5] format --- .../lib/list_tile/cupertino_list_tile.0.dart | 9 +++- .../lib/magnifier/text_magnifier.0.dart | 18 +++++--- .../cupertino_context_menu.0_test.dart | 3 +- .../cupertino_context_menu.1_test.dart | 3 +- .../list_tile/cupertino_list_tile.0_test.dart | 18 ++++++-- .../test/magnifier/text_magnifier.0_test.dart | 42 ++++++++++++++----- 6 files changed, 70 insertions(+), 23 deletions(-) diff --git a/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart b/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart index e44653df5c0d..7cbd61d5c355 100644 --- a/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart +++ b/packages/cupertino_ui/example/lib/list_tile/cupertino_list_tile.0.dart @@ -24,11 +24,16 @@ class CupertinoListTileExample extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoPageScaffold( - navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoListTile Sample')), + navigationBar: const CupertinoNavigationBar( + middle: Text('CupertinoListTile Sample'), + ), child: ListView( children: const [ CupertinoListTile(title: Text('One-line CupertinoListTile')), - CupertinoListTile(leading: FlutterLogo(), title: Text('One-line with leading widget')), + CupertinoListTile( + leading: FlutterLogo(), + title: Text('One-line with leading widget'), + ), CupertinoListTile( title: Text('One-line with trailing widget'), trailing: Icon(CupertinoIcons.ellipsis_vertical), diff --git a/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart b/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart index d858481d0487..8135e8257a0a 100644 --- a/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart +++ b/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart @@ -9,13 +9,18 @@ import 'package:cupertino_ui/cupertino_ui.dart'; void main() => runApp(const TextMagnifierExampleApp(text: 'Hello world!')); class TextMagnifierExampleApp extends StatefulWidget { - const TextMagnifierExampleApp({super.key, this.textDirection = TextDirection.ltr, required this.text}); + const TextMagnifierExampleApp({ + super.key, + this.textDirection = TextDirection.ltr, + required this.text, + }); final TextDirection textDirection; final String text; @override - State createState() => _TextMagnifierExampleAppState(); + State createState() => + _TextMagnifierExampleAppState(); } class _TextMagnifierExampleAppState extends State { @@ -33,8 +38,9 @@ class _TextMagnifierExampleAppState extends State { // Create a custom magnifier configuration that // this `TextField` will use to build a magnifier with. magnifierConfiguration: TextMagnifierConfiguration( - magnifierBuilder: (_, _, ValueNotifier magnifierInfo) => - CustomMagnifier(magnifierInfo: magnifierInfo), + magnifierBuilder: + (_, _, ValueNotifier magnifierInfo) => + CustomMagnifier(magnifierInfo: magnifierInfo), ), controller: controller, ), @@ -103,7 +109,9 @@ class CustomMagnifier extends StatelessWidget { focalPointOffset: Offset(0, magnifierSize.height / 2), // Decorate it however we'd like! decoration: const MagnifierDecoration( - shape: StarBorder(side: BorderSide(color: Color(0xFF00FF00), width: 2)), + shape: StarBorder( + side: BorderSide(color: Color(0xFF00FF00), width: 2), + ), ), size: magnifierSize, ), diff --git a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart index b6b104e475b2..c848e51b87f4 100644 --- a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart +++ b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.0_test.dart @@ -3,7 +3,8 @@ // found in the LICENSE file. import 'package:cupertino_ui/cupertino_ui.dart'; -import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.0.dart' as example; +import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.0.dart' + as example; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart index 1498fff89a72..c2443d0f938a 100644 --- a/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart +++ b/packages/cupertino_ui/example/test/context_menu/cupertino_context_menu.1_test.dart @@ -3,7 +3,8 @@ // found in the LICENSE file. import 'package:cupertino_ui/cupertino_ui.dart'; -import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.1.dart' as example; +import 'package:cupertino_ui_examples/context_menu/cupertino_context_menu.1.dart' + as example; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart b/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart index 95e536237f57..915476b74f03 100644 --- a/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart +++ b/packages/cupertino_ui/example/test/list_tile/cupertino_list_tile.0_test.dart @@ -3,11 +3,14 @@ // found in the LICENSE file. import 'package:cupertino_ui/cupertino_ui.dart'; -import 'package:cupertino_ui_examples/list_tile/cupertino_list_tile.0.dart' as example; +import 'package:cupertino_ui_examples/list_tile/cupertino_list_tile.0.dart' + as example; import 'package:flutter_test/flutter_test.dart'; void main() { - testWidgets('CupertinoListTile respects properties', (WidgetTester tester) async { + testWidgets('CupertinoListTile respects properties', ( + WidgetTester tester, + ) async { await tester.pumpWidget(const example.CupertinoListTileApp()); expect(find.text('CupertinoListTile Sample'), findsOne); @@ -25,7 +28,14 @@ void main() { expect(find.byIcon(CupertinoIcons.ellipsis_vertical), findsNWidgets(3)); expect(find.byIcon(CupertinoIcons.info), findsOne); - final Finder tileWithBackgroundFinder = find.byKey(const Key('CupertinoListTile with background color')); - expect(tester.firstWidget(tileWithBackgroundFinder).backgroundColor, const Color(0xFF0000FF)); + final Finder tileWithBackgroundFinder = find.byKey( + const Key('CupertinoListTile with background color'), + ); + expect( + tester + .firstWidget(tileWithBackgroundFinder) + .backgroundColor, + const Color(0xFF0000FF), + ); }); } diff --git a/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart b/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart index 8806586e1882..18bc810ad267 100644 --- a/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart +++ b/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart @@ -4,29 +4,42 @@ import 'package:flutter/rendering.dart'; import 'package:cupertino_ui/cupertino_ui.dart'; -import 'package:cupertino_ui_examples/magnifier/text_magnifier.0.dart' as example; +import 'package:cupertino_ui_examples/magnifier/text_magnifier.0.dart' + as example; import 'package:flutter_test/flutter_test.dart'; -List _globalize(Iterable points, RenderBox box) { +List _globalize( + Iterable points, + RenderBox box, +) { return points.map((TextSelectionPoint point) { return TextSelectionPoint(box.localToGlobal(point.point), point.direction); }).toList(); } -RenderEditable _findRenderEditable>(WidgetTester tester) { - return (tester.state(find.byType(CupertinoTextField)) as TextSelectionGestureDetectorBuilderDelegate) +RenderEditable _findRenderEditable>( + WidgetTester tester, +) { + return (tester.state(find.byType(CupertinoTextField)) + as TextSelectionGestureDetectorBuilderDelegate) .editableTextKey .currentState! .renderEditable; } -Offset _textOffsetToPosition>(WidgetTester tester, int offset) { +Offset _textOffsetToPosition>( + WidgetTester tester, + int offset, +) { final RenderEditable renderEditable = _findRenderEditable(tester); final List endpoints = renderEditable .getEndpointsForSelection(TextSelection.collapsed(offset: offset)) .map( - (TextSelectionPoint point) => TextSelectionPoint(renderEditable.localToGlobal(point.point), point.direction), + (TextSelectionPoint point) => TextSelectionPoint( + renderEditable.localToGlobal(point.point), + point.direction, + ), ) .toList(); @@ -73,23 +86,32 @@ void main() { testWidgets( 'should show custom magnifier on drag', (WidgetTester tester) async { - await tester.pumpWidget(const example.TextMagnifierExampleApp(text: defaultText)); + await tester.pumpWidget( + const example.TextMagnifierExampleApp(text: defaultText), + ); await showMagnifier(tester, defaultText.indexOf('e')); expect(find.byType(example.CustomMagnifier), findsOneWidget); - await expectLater(find.byType(example.TextMagnifierExampleApp), matchesGoldenFile('text_magnifier.0_test.png')); + await expectLater( + find.byType(example.TextMagnifierExampleApp), + matchesGoldenFile('text_magnifier.0_test.png'), + ); }, variant: const TargetPlatformVariant({.iOS, .android}), // This image is flaky. https://github.com/flutter/flutter/issues/144350 skip: true, ); - testWidgets('should show custom magnifier in RTL', (WidgetTester tester) async { + testWidgets('should show custom magnifier in RTL', ( + WidgetTester tester, + ) async { const String text = 'أثارت زر'; const String textToTapOn = 'ت'; - await tester.pumpWidget(const example.TextMagnifierExampleApp(textDirection: .rtl, text: text)); + await tester.pumpWidget( + const example.TextMagnifierExampleApp(textDirection: .rtl, text: text), + ); await showMagnifier(tester, text.indexOf(textToTapOn)); From 8ea52a5b4aa3d9cb9494935d67afc43af77979d3 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Fri, 17 Jul 2026 14:10:11 +0200 Subject: [PATCH 5/5] fix test by using long press instead --- .../lib/magnifier/text_magnifier.0.dart | 2 +- .../test/magnifier/text_magnifier.0_test.dart | 47 ++++--------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart b/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart index 8135e8257a0a..c4aacbb52e31 100644 --- a/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart +++ b/packages/cupertino_ui/example/lib/magnifier/text_magnifier.0.dart @@ -36,7 +36,7 @@ class _TextMagnifierExampleAppState extends State { child: CupertinoTextField( textDirection: widget.textDirection, // Create a custom magnifier configuration that - // this `TextField` will use to build a magnifier with. + // this `CupertinoTextField` will use to build a magnifier with. magnifierConfiguration: TextMagnifierConfiguration( magnifierBuilder: (_, _, ValueNotifier magnifierInfo) => diff --git a/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart b/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart index 18bc810ad267..d7aafc35fc33 100644 --- a/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart +++ b/packages/cupertino_ui/example/test/magnifier/text_magnifier.0_test.dart @@ -8,15 +8,6 @@ import 'package:cupertino_ui_examples/magnifier/text_magnifier.0.dart' as example; import 'package:flutter_test/flutter_test.dart'; -List _globalize( - Iterable points, - RenderBox box, -) { - return points.map((TextSelectionPoint point) { - return TextSelectionPoint(box.localToGlobal(point.point), point.direction); - }).toList(); -} - RenderEditable _findRenderEditable>( WidgetTester tester, ) { @@ -47,40 +38,16 @@ Offset _textOffsetToPosition>( } void main() { - const Duration durationBetweenActions = Duration(milliseconds: 20); const String defaultText = 'I am a magnifier, fear me!'; Future showMagnifier(WidgetTester tester, int textOffset) async { assert(textOffset >= 0); final Offset tapOffset = _textOffsetToPosition(tester, textOffset); - // Double tap 'Magnifier' word to show the selection handles. + // Long press to show the magnifier. final TestGesture testGesture = await tester.startGesture(tapOffset); - await tester.pump(durationBetweenActions); - await testGesture.up(); - await tester.pump(durationBetweenActions); - await testGesture.down(tapOffset); - await tester.pump(durationBetweenActions); - await testGesture.up(); - await tester.pumpAndSettle(); - - final TextEditingController controller = tester - .firstWidget(find.byType(CupertinoTextField)) - .controller!; - - final TextSelection selection = controller.selection; - final RenderEditable renderEditable = _findRenderEditable(tester); - final List endpoints = _globalize( - renderEditable.getEndpointsForSelection(selection), - renderEditable, - ); - - final Offset handlePos = endpoints.last.point + const Offset(10.0, 10.0); - - final TestGesture gesture = await tester.startGesture(handlePos); - - await gesture.moveTo(_textOffsetToPosition(tester, defaultText.length - 2)); - await tester.pump(); + addTearDown(testGesture.removePointer); + await tester.pump(const Duration(milliseconds: 600)); } testWidgets( @@ -89,8 +56,10 @@ void main() { await tester.pumpWidget( const example.TextMagnifierExampleApp(text: defaultText), ); + final int textOffset = defaultText.indexOf('e'); + + await showMagnifier(tester, textOffset); - await showMagnifier(tester, defaultText.indexOf('e')); expect(find.byType(example.CustomMagnifier), findsOneWidget); await expectLater( @@ -113,7 +82,9 @@ void main() { const example.TextMagnifierExampleApp(textDirection: .rtl, text: text), ); - await showMagnifier(tester, text.indexOf(textToTapOn)); + final int textOffset = text.indexOf(textToTapOn); + + await showMagnifier(tester, textOffset); expect(find.byType(example.CustomMagnifier), findsOneWidget); });