所以我想在这里做的是在 InteractiveViewer 的缩放比例时按比例更改 SingleChildScrollView 的大小。例如: scale 1.0 = 滚动视图的宽度为 1000,缩放 2.0 = 滚动视图的宽度为 2000 等等。我似乎无法直接从文档中找出如何做到这一点。所以我通过获取属性(比例)本身的值并重新渲染 SingleChildScrollView 小部件来考虑它,但我似乎也找不到任何方法来做到这一点。如果需要更多说明,请随时提出。谢谢!
您可以像这样获得实际和持久的比例值:
class InteractiveViewerTest extends StatefulWidget {
@override
_InteractiveViewerTestState createState() => _InteractiveViewerTestState();
}
class _InteractiveViewerTestState extends State<InteractiveViewerTest> {
TransformationController _transformationController =
TransformationController();
@override
Widget build(BuildContext context) {
return InteractiveViewer(
minScale: 0.5,
maxScale: 2.0,
transformationController: _transformationController,
onInteractionEnd: (details) {
// Details.scale can give values below 0.5 or above 2.0 and resets to 1
// Use the Controller Matrix4 to get the correct scale.
double correctScaleValue = _transformationController.value.getMaxScaleOnAxis();
},
child: Container(
width: 100,
height: 100,
color: Colors.blue,
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
onInteractionUpdate当用户更新小部件上的平移或缩放手势时调用。这样你就可以scale从得到电流callback。
我在下面添加了演示代码:
InteractiveViewer(
transformationController: transformationController,
onInteractionUpdate: (ScaleUpdateDetails details){ // get the scale from the ScaleUpdateDetails callback
var myScale = details.scale;
print(myScale); // print the scale here
},
boundaryMargin: EdgeInsets.all(20.0),
minScale: 0.1,
maxScale: 4.6,
scaleEnabled: true,
panEnabled: true,
child: ClipRRect(
borderRadius: BorderRadius.circular(18.0),
child: Image.asset('images/user_picture.png'),
),
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1045 次 |
| 最近记录: |