Jan*_*aka 7 interactive zooming flutter
我正在使用 InteractiveViewer 来显示视频。它工作正常。但我想设置初始缩放级别。
有没有办法做到这一点?
return InteractiveViewer(
minScale: 1,
maxScale: 4,
constrained: false,
child: Container(
color: Colors.red,
width: 320,
height: 180,
child: widget.remoteVideoRenderer(),
),
);
Run Code Online (Sandbox Code Playgroud)
Amo*_*hua 16
我能够做到这一点,并取得了不同程度的成功,就像这样(感谢@pskink为我指明了正确的方向):
final viewTransformationController = TransformationController();
@override
void initState() {
final zoomFactor = 2.0;
final xTranslate = 300.0;
final yTranslate = 300.0;
viewTransformationController.value.setEntry(0, 0, zoomFactor);
viewTransformationController.value.setEntry(1, 1, zoomFactor);
viewTransformationController.value.setEntry(2, 2, zoomFactor);
viewTransformationController.value.setEntry(0, 3, -xTranslate);
viewTransformationController.value.setEntry(1, 3, -yTranslate);
super.initState();
}
@override
Widget build(BuildContext context) {
return InteractiveViewer(
transformationController: viewTransformationController,
minScale: 0.1,
maxScale: 6,
child: // ....
);
}
Run Code Online (Sandbox Code Playgroud)
viewTransformationController.value是一个应用于视图的 4x4 矩阵,它对平移/旋转/缩放进行编码。矩阵中这些变换的表示可能记录在某处(和/或只是射影/仿射几何的标准),但我找不到它们,所以我只是在缩放/平移时将它们打印出来,直到每个条目的角色变成清除。
如果您只是将缩放系数设置为 2 并且不进行平移,您将在小部件的左上角进行放大。
initState()请注意,您无法使用 方法访问窗口尺寸MediaQuery.of(context),如果您想要放大窗口中间,这会有些不方便。我还没有找到一个好的方法来做到这一点。
| 归档时间: |
|
| 查看次数: |
5390 次 |
| 最近记录: |