通过 Interactive viewer
文档,我了解到我们可以使用 toScene
方法自动滚动到 Interactive viewer
中的特定位置。但是我尝试过但一切都是徒劳的。如何根据交互式查看器中的位置自动滚动到偏移量
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
class MyPlanet extends StatefulWidget {
@override
_MyPlanetState createState() => _MyPlanetState();
}
class _MyPlanetState extends State<MyPlanet> {
final TransformationController transformationController =
TransformationController();
@override
void initState() {
SchedulerBinding.instance.addPostFrameCallback((_) async {
Timer(Duration(seconds: 5), () {
setState(() {
transformationController.value = Matrix4.identity()
..translate(800, 0.0);
transformationController.toScene(Offset(800, 0.0));
});
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return InteractiveViewer(
minScale: 0.5,
maxScale: 1,
constrained: false,
transformationController: transformationController,
child: Container(
height: 896,
width: 2000,
child: Image.asset(
'assets/images/rain_forest.png',
fit: BoxFit.cover,
height: double.infinity,
),
),
);
}
}
最佳答案
谢谢@pskink。
可以使用 TransformationController
和 matrix4
@override
void initState() {
TransformationController transformationController =
TransformationController();
transformationController.value = Matrix4.identity()
..translate(-200.0, 0.0); // translate(x,y);
}
关于flutter - 自动滚动到交互式查看器中的偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65898533/