通过 Interactive viewer
文档,我开始知道我们可以使用 Interactive viewer
方法自动滚动到 toScene
中的特定位置。但我尝试过但一切都白费了。如何自动滚动到给定交互式查看器中的位置的偏移
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,
),
),
);
}
}
答案 0 :(得分:1)
谢谢@pskink。
可以使用 TransformationController
和 matrix4
@override
void initState() {
TransformationController transformationController =
TransformationController();
transformationController.value = Matrix4.identity()
..translate(-200.0, 0.0); // translate(x,y);
}
答案 1 :(得分:0)
试试
@override
void initState() {
SchedulerBinding.instance.addPostFrameCallback((_) async {
transformationController.toScene(Offset(100, 0));
});
super.initState();
}