【发布时间】:2021-05-30 02:32:44
【问题描述】:
我正在尝试渲染比 ViewBox 更大的 SVG 图像。为此,我使用了flutter_svg 0.19.0。由于某些原因,图像仅缩放到父小部件的边框。但是,如果我指定的尺寸小于 ViewBox,则图像会正确缩小。
创建 SVG 小部件:
void setNewImage(String path) {
setState(() {
svg = SvgPicture.asset(
path,
alignment: Alignment.center,
allowDrawingOutsideViewBox: true,
width: 3000.0,
height: 5000.0,
clipBehavior: Clip.none,
);
});
}
父小部件:
Scaffold(
resizeToAvoidBottomPadding: false,
//avoid resize when keyboard is visible
resizeToAvoidBottomInset: false,
backgroundColor: Colors.transparent,
body: ClipRRect(
child: Container(
color: Colors.transparent,
child: svg
)
)
)
您知道我该如何处理这个问题吗?使用 SizedBox,指定宽高的 Container 也不行。
编辑: 我通过将 svg Widget 插入到 Transform.scale() 小部件中找到了解决方案。
Scaffold(
resizeToAvoidBottomPadding: false,
//avoid resize when keyboard is visible
resizeToAvoidBottomInset: false,
backgroundColor: Colors.transparent,
body: ClipRRect(
child: Container(
color: Colors.transparent,
child: Transform.scale(
scale: 2,
alignment: Alignment.topLeft,
child: svg)
)
)
)
【问题讨论】: