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
This commit is contained in:
RamonFarizel
2024-09-27 20:13:19 -03:00
committed by GitHub
parent 96291fc0c4
commit 1290ab42d1
2 changed files with 69 additions and 1 deletions

View File

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

View File

@@ -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<RawMagnifier>().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<RawMagnifier>().having(
(RawMagnifier t) => t.magnificationScale,
'magnificationScale',
2,
),
);
});
});
});
}