CupertinoMagnifier class

A RawMagnifier used for magnifying text in cases where a user's finger may be blocking the point of interest, like a selection handle.

This sample demonstrates how to use CupertinoMagnifier.

import 'package:cupertino_ui/cupertino_ui.dart';

/// Flutter code sample for [CupertinoMagnifier].

void main() => runApp(const CupertinoMagnifierApp());

class CupertinoMagnifierApp extends StatelessWidget {
  const CupertinoMagnifierApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      theme: CupertinoThemeData(brightness: .light),
      home: CupertinoMagnifierExample(),
    );
  }
}

class CupertinoMagnifierExample extends StatefulWidget {
  const CupertinoMagnifierExample({super.key});

  @override
  State<CupertinoMagnifierExample> createState() =>
      _CupertinoMagnifierExampleState();
}

class _CupertinoMagnifierExampleState extends State<CupertinoMagnifierExample> {
  static const double magnifierRadius = 50.0;
  Offset dragGesturePosition = .zero;

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        middle: Text('CupertinoMagnifier Sample'),
      ),
      child: Center(
        child: Column(
          mainAxisAlignment: .center,
          children: <Widget>[
            const Text('Drag on the logo!'),
            RepaintBoundary(
              child: Stack(
                children: <Widget>[
                  GestureDetector(
                    onPanUpdate: (DragUpdateDetails details) {
                      setState(() {
                        dragGesturePosition = details.localPosition;
                      });
                    },
                    onPanDown: (DragDownDetails details) {
                      setState(() {
                        dragGesturePosition = details.localPosition;
                      });
                    },
                    child: const FlutterLogo(size: 200),
                  ),
                  Positioned(
                    left: dragGesturePosition.dx - magnifierRadius,
                    top: dragGesturePosition.dy - magnifierRadius,
                    child: const CupertinoMagnifier(
                      magnificationScale: 1.5,
                      borderRadius: .all(Radius.circular(magnifierRadius)),
                      additionalFocalPointOffset: Offset(0, -magnifierRadius),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

CupertinoMagnifier is a wrapper around RawMagnifier that handles styling and transitions.

This magnifying glass is useful for scenarios on mobile devices where the user's finger may be covering part of the screen where a granular action is being performed, such as navigating a small cursor with a drag gesture, on an image or text.

See also:

Inheritance

Constructors

CupertinoMagnifier({Key? key, Size size = kDefaultSize, BorderRadius borderRadius = const BorderRadius.all(Radius.elliptical(60, 50)), Offset additionalFocalPointOffset = Offset.zero, List<BoxShadow> shadows = const <BoxShadow>[BoxShadow(color: Color.fromARGB(25, 0, 0, 0), blurRadius: 11, spreadRadius: 0.2, blurStyle: BlurStyle.outer)], Clip clipBehavior = Clip.none, BorderSide borderSide = const BorderSide(color: Color.fromARGB(255, 0, 124, 255), width: 2.0), Animation<double>? inOutAnimation, double magnificationScale = 1.0})
Creates a RawMagnifier in the Cupertino style.
const

Properties

additionalFocalPointOffset → Offset
Any additional focal point offset, applied over the regular focal point offset defined in kMagnifierAboveFocalPoint.
final
borderRadius → BorderRadius
The border radius of this magnifier.
final
borderSide → BorderSide
The border, or "rim", of this magnifier.
final
clipBehavior → Clip
Whether and how to clip the shadows that render inside the loupe.
final
hashCode → int
The hash code for this object.
no setterinherited
inOutAnimation → Animation<double>?
This RawMagnifier's controller.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
magnificationScale → double
The magnification scale for the magnifier.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
shadows → List<BoxShadow>
A list of shadows cast by the Magnifier.
final
size → Size
The size of this magnifier.
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

kDefaultSize → const Size
The default size of the magnifier.
kMagnifierAboveFocalPoint → const double
The vertical offset that the magnifier is along the Y axis above the focal point.