颤振放大倍率



我正在尝试在颤振中实现应用程序Eye Color Changer - Camera的放大(例如,当您在iOS中移动文本光标时,您会看到光标周围区域的缩放预览)。这是我的代码:

class _MyHomePageState extends State<MyHomePage> {
  Offset position;
  @override
  void initState() {
    super.initState();
    position = Offset(100, 100);
  }
  @override
  Widget build(BuildContext context) {
    getDraggable({withPreview = false}) {
      return Column(
        children: <Widget>[
          Opacity(
            opacity: withPreview ? 1 : 0,
            child: Container(
              width: 100,
              height: 100,
              color: Colors.red,
            ),
          ),
          Image.asset("eye.png"),
        ],
      );
    }
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage("face.jpg"),
              ),
            ),
            child: null,
          ),
          Positioned(
            left: position.dx,
            top: position.dy,
            child: Container(
              child: Draggable(
                child: getDraggable(),
                feedback: getDraggable(withPreview: true),
                childWhenDragging: Container(),
                onDraggableCanceled: (Velocity velocity, Offset offset) {
                  setState(() => position = offset);
                },
              ),
            ),
          ),
          Positioned(
            left: 30,
            bottom: 50,
            child: Text(
                "x: ${position.dx.toStringAsFixed(2)}   y: ${position.dy.toStringAsFixed(2)}"),
          )
        ],
      ),
    );
  }
}

预览:https://i.stack.imgur.com/jFDM0.png

我需要显示eye.png(那个白色圆圈)图像的放大镜,而不是那个红色容器。

放大倍率可以在 Flutter 中使用 RawMagnifier widget 实现。文档中提供了一个示例。它还演示了可以自定义放大镜小部件以适合您的用例。

最新更新