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, + ), + ); + }); + }); }); }