You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何在Stack内垂直拉伸SVG以匹配Stack高度?

问题:让SVG适配Stack的高度(由Stack最大子项决定)

我尝试过多种方法,最接近的是使用Position.fill,但它会双向拉伸SVG。

以下是我最新的代码,SVG未被拉伸,仍保持原尺寸:

Widget build(BuildContext context) => 
Padding(
  padding: EdgeInsets.only(left: 16, right: 16),
  child: Stack(children: [
    Flex(direction: Axis.vertical, children: <Widget>[
      SvgPicture.asset(
        'assets/icons/comments/lineVerticalReply.svg',
        fit: BoxFit.fitHeight,
      ),
    ]),
    Column(children: [
      //... 示例替代内容:
      SizedBox(width: 200, height:200)
    ]),
  ]),
);

我尝试过的方案:

  • Flex结合Expanded
  • FittedBox
  • 带BoxConstraints的Container
  • Positioned.fill <-- 最接近的尝试
  • 上述方案的组合及其他已遗忘的方法

问题在于Stack的尺寸由SVG的同级子组件决定,我需要让SVG的高度适配Stack的高度(由Stack中最大子项决定),请问该如何实现?


内容的提问来源于stack exchange,提问作者MetaStack

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 01:52:02