From 1290ab42d1862bb58b10bf728d8992b739077d17 Mon Sep 17 00:00:00 2001 From: RamonFarizel <45459898+RamonFarizel@users.noreply.github.com> Date: Fri, 27 Sep 2024 20:13:19 -0300 Subject: [PATCH] Add magnificationScale to CupertinoMagnifier for Zoom Effect (#155276) Add `magnificationScale `to `CupertinoMagnifier` for Zoom Effect The CupertinoMagnifier widget is not displaying the expected zoom effect. This issue arises because the widget internally wraps the RawMagnifier, which has its magnificationScale attribute set to the default value of 1. As a result, no magnification is applied, and the zoom effect is absent. Fixes #155275 --- .../flutter/lib/src/cupertino/magnifier.dart | 10 +++- .../test/cupertino/magnifier_test.dart | 60 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/cupertino/magnifier.dart b/packages/flutter/lib/src/cupertino/magnifier.dart index 7fc97f6f81..2227595276 100644 --- a/packages/flutter/lib/src/cupertino/magnifier.dart +++ b/packages/flutter/lib/src/cupertino/magnifier.dart @@ -258,7 +258,9 @@ class CupertinoMagnifier extends StatelessWidget { this.borderSide = const BorderSide(color: Color.fromARGB(255, 232, 232, 232)), this.inOutAnimation, - }); + this.magnificationScale = 1.0, + }) : assert(magnificationScale > 0, 'The magnification scale should be greater than zero.'); + /// A list of shadows cast by the [Magnifier]. /// @@ -334,6 +336,11 @@ class CupertinoMagnifier extends StatelessWidget { /// point offset defined in [kMagnifierAboveFocalPoint]. final Offset additionalFocalPointOffset; + /// The magnification scale for the magnifier. + /// + /// Defaults to 1.0, which indicates that the magnifier does not apply any magnification. + final double magnificationScale; + @override Widget build(BuildContext context) { Offset focalPointOffset = @@ -359,6 +366,7 @@ class CupertinoMagnifier extends StatelessWidget { shadows: shadows, ), clipBehavior: clipBehavior, + magnificationScale: magnificationScale, ), ); } diff --git a/packages/flutter/test/cupertino/magnifier_test.dart b/packages/flutter/test/cupertino/magnifier_test.dart index 01e7794326..cc241a31a4 100644 --- a/packages/flutter/test/cupertino/magnifier_test.dart +++ b/packages/flutter/test/cupertino/magnifier_test.dart @@ -263,5 +263,65 @@ void main() { expect(magnifierController.overlayEntry, isNotNull); }); }); + + group('magnificationScale', () { + testWidgets('Throws assertion error when magnificationScale is zero', (WidgetTester tester) async { + expect(() => MaterialApp( + home: Scaffold( + body: CupertinoMagnifier( + magnificationScale: 0, + ), + ), + ), throwsAssertionError); + }); + + testWidgets('Throws assertion error when magnificationScale is negative', (WidgetTester tester) async { + expect(() => MaterialApp( + home: Scaffold( + body: CupertinoMagnifier( + magnificationScale: -1, + ), + ), + ), throwsAssertionError); + }); + + testWidgets('CupertinoMagnifier magnification scale defaults to 1', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold(body: CupertinoMagnifier()), + ), + ); + + expect( + tester.widget(find.byType(RawMagnifier)), + isA().having( + (RawMagnifier t) => t.magnificationScale, + 'magnificationScale', + 1, + ), + ); + }); + + testWidgets('Magnification scale argument is passed to the RawMagnifier', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: CupertinoMagnifier( + magnificationScale: 2, + ), + ), + ), + ); + + expect( + tester.widget(find.byType(RawMagnifier)), + isA().having( + (RawMagnifier t) => t.magnificationScale, + 'magnificationScale', + 2, + ), + ); + }); + }); }); }