我正在尝试在应用程序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
(白色圆圈)图像的放大镜。