自动滚动到交互式查看器中的偏移量

AutoScroll to a offset in interactive viewer in flutter

通过 Interactive viewer 文档,我了解到我们可以使用 toScene method.But 自动滚动到 Interactive viewer 中的特定位置,但我尝试了 [=17] 中的所有内容=] 自动滚动到给定交互式查看器中的位置的偏移量

 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。 可以使用 TransformationControllermatrix4

实现交互式查看器中的自动滚动
@override
void initState() {
TransformationController transformationController =
      TransformationController();
transformationController.value = Matrix4.identity()
        ..translate(-200.0, 0.0); // translate(x,y);
}