【问题标题】:Flutter: How can I limit children width of SliverChildListDelegate?Flutter:如何限制 SliverChildListDelegate 的子级宽度?
【发布时间】:2022-12-29 19:48:48
【问题描述】:

我有一个 Flutter 项目,其中 SliverListCustomScrollView 中使用。 SliverList 将其 delegate 属性设置为 SliverChildListDelegateSliverChildListDelegate 填充了宽度设置为 200 的小部件。在构建应用程序时,小部件无论如何都会占用整个应用程序的宽度。如果将这些相同的小部件放在SingleChildScrollView 下的Column 中,宽度将被尊重并设置为 200。如何限制 SliverChildListDelegate 内的子小部件的宽度?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    这看起来更像是一个技巧而不是官方解决方案。我只是用 Row 包裹它,然后把 Widget 放在 2 个 Spacer 之间。例如:

    SliverList(
      delegate: SliverChildListDelegate([
        Row(
          children: [
            Spacer(),
            Container(
              height: 6,
              width: 200,
              color: Colors.red,
            ),
            Spacer(),
          ],
        ),
      ]),
    )
    

    【讨论】:

      猜你喜欢
      • 2023-02-06
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      相关资源
      最近更新 更多