【问题标题】:Unable to Center InteractiveViewer and panning in Flutter Web app无法将 InteractiveViewer 居中并在 Flutter Web 应用程序中平移
【发布时间】:2021-08-28 15:08:54
【问题描述】:

我尝试在交互式查看器中显示图像列表,以便可以双向平移。即使放置在 Center 小部件内,interactiveviewer 也会左对齐。尝试将 constrained 属性设置为 true 并在顶部中心添加一个溢出框,就像在颤振源中所做的那样。但是,我无法平移图像列表并放大/缩小到旧位置。此问题仅存在于 Flutter Web 应用中。

请帮我解决这个问题。

Center(
        child: InteractiveViewer(
          constrained: false,
          child: Column(
            key: _columnKey,
            children: List<Widget>.generate(
                10, (int index) {
              return Image.asset('assets/image.png');
            }),
          ),
        ),
      )

【问题讨论】:

    标签: image flutter center


    【解决方案1】:

    这是 Flutter 团队的“预期”行为,您可以在 InteractiveViewer 小部件的代码中看到它创建了一个对齐设置为左上角的 OverflowBox。您可以在本地文件中对此进行注释,以查看 InteractiveViewer 是否会居中。但是,要真正使小部件正确居中,一种解决方案(就像我最终做的那样)是重新创建 InteractiveViewer 并编辑您需要的代码。

    另请参阅:InteractiveViewer with constrained: false ignores Center widget and alignment #90517

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 2019-10-25
      • 2021-09-27
      • 1970-01-01
      相关资源
      最近更新 更多