scrollTo method
Scrolls to the specified offset
final GlobalKey<InteractiveScrollViewerState> _interactiveViewerKey =
GlobalKey();
TransformationController transformationController=
TransformationController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('InteractiveScrollViewer'),
actions: <Widget>[
IconButton(
icon: const Icon(
Icons.arrow_circle_down,
color: Colors.white,
),
onPressed: () {
_interactiveViewerKey.currentState?.scrollTo(Offset(150,2000));
},
),
],
),
body: InteractiveScrollViewer(
Image.network('https://picsum.photos/250?image=9'),
key: _interactiveViewerKey,
transformationController: transformationController,
));
}
Implementation
void scrollTo(Offset offset) {
if (widget.transformationController != null) {
final Offset previousOffset =
widget.transformationController!.toScene(Offset.zero);
widget.transformationController?.value =
widget.transformationController!.value.clone()
..translate(
previousOffset.dx - offset.dx, previousOffset.dy - offset.dy);
}
}