CupertinoTextMagnifier class

A CupertinoMagnifier 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 CupertinoTextMagnifier.

import 'package:cupertino_ui/cupertino_ui.dart';

/// Flutter code sample for [CupertinoTextMagnifier].

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

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

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

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

  @override
  State<CupertinoTextMagnifierExampleApp> createState() =>
      _CupertinoTextMagnifierExampleAppState();
}

class _CupertinoTextMagnifierExampleAppState
    extends State<CupertinoTextMagnifierExampleApp> {
  final MagnifierController _magnifierController = MagnifierController();
  final TextEditingController _textEditingController = TextEditingController(
    text: 'Hello world!',
  );

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        middle: Text('CupertinoTextMagnifier Sample'),
      ),
      child: Padding(
        padding: const .symmetric(horizontal: 48.0),
        child: Center(
          child: CupertinoTextField(
            magnifierConfiguration: TextMagnifierConfiguration(
              magnifierBuilder:
                  (_, _, ValueNotifier<MagnifierInfo> magnifierInfo) {
                    return CupertinoTextMagnifier(
                      controller: _magnifierController,
                      magnifierInfo: magnifierInfo,
                    );
                  },
            ),
            controller: _textEditingController,
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    _textEditingController.dispose();
    super.dispose();
  }
}

Delegates styling to CupertinoMagnifier with its position depending on magnifierInfo.

Specifically, the CupertinoTextMagnifier follows the following rules. CupertinoTextMagnifier:

  • is positioned horizontally inside the screen width, with horizontalScreenEdgePadding padding.
  • is hidden if a gesture is detected hideBelowThreshold units below the line that the magnifier is on, shown otherwise.
  • follows the x coordinate of the gesture directly (with respect to rule 1).
  • has some vertical drag resistance; i.e. if a gesture is detected k units below the field, then has vertical offset dragResistance * k.
Inheritance

Constructors

CupertinoTextMagnifier({Key? key, Curve animationCurve = Curves.easeOut, required MagnifierController controller, double dragResistance = 10.0, double hideBelowThreshold = 48.0, double horizontalScreenEdgePadding = 10.0, required ValueNotifier<MagnifierInfo> magnifierInfo})
Constructs a RawMagnifier in the Cupertino style, positioning with respect to magnifierInfo.
const

Properties

animationCurve → Curve
The curve used for the in / out animations.
final
controller → MagnifierController
This magnifier's controller.
final
dragResistance → double
A drag resistance on the downward Y position of the lens.
final
hashCode → int
The hash code for this object.
no setterinherited
hideBelowThreshold → double
The difference in Y between the gesture position and the caret center so that the magnifier hides itself.
final
horizontalScreenEdgePadding → double
The padding on either edge of the screen that any part of the magnifier cannot exist past.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
magnifierInfo → ValueNotifier<MagnifierInfo>
CupertinoTextMagnifier will determine its own positioning based on the MagnifierInfo of this notifier.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<CupertinoTextMagnifier>
Creates the mutable state for this widget at a given location in the tree.
override
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