【问题标题】:Flutter - Selected items move to top of ListViewFlutter - 选定的项目移动到 ListView 的顶部
【发布时间】:2018-12-29 18:53:37
【问题描述】:

我一直在寻找一种方法来永久将所选项目移动到 ListView 的顶部。

这可以通过在ListView 元素旁边按下iconbutton 并让该元素在refresh 上移动到顶部来工作。

如果可能,我希望图标按钮在启用时变为enabled(即发光/亮起),在禁用时变为disabled(灰显,但仍可按下)。

我无法将我的所有代码都放入这个问题中,所以所有这些以及 _getListItemUi 都可以在以下位置获得:https://github.com/Jak3-02/myproject2

这是我当前的 ListView 的样子:

Widget _cryptoWidget() {
    return new Container(
        child: new Column(
          children: <Widget>[
            new Flexible(
              child: new ListView.builder(
                itemCount: _currencies.length,
                itemBuilder: (BuildContext context, int index) {
                  final int i = index ~/ 2;
                  final Crypto currency = _currencies[i];
                  final MaterialColor color = _colors[i % _colors.length];
                  if (index.isOdd) {
                    return new Divider();
                  }
                  return _getListItemUi(currency, color);
                },
              ),
            ),
          ],
        )
      );
  }

谢谢,所有的想法都值得赞赏。 :)

【问题讨论】:

  • 您可以有一个选定项目的列表,这些项目用作ListView 的第一个子项。
  • 你能告诉我如何将它编码到我的项目中吗?另外,我如何能够允许用户选择要添加到所选项目列表中的项目?

标签: android ios listview dart flutter


【解决方案1】:

这听起来很像一个课堂项目,所以我会为你指出正确的方向来自己解决这个问题。

请注意代码中的项目生成器。它读取 _currencies 列表并构建相应的小部件。 如果你在 _currencies 中 rearranged the items 再次运行这段代码会发生什么?

当 _currencies 列表发生变化时,如何让 _cryptoWidget 重绘? 你会使用有状态小部件还是无状态小部件?当数据发生变化时,其中哪一个会自行重绘?

您想要一个在启用和禁用时看起来不同的可点击图标。 你看过Widget Catalog吗?

有了这些笔记,你应该可以很容易地解决这个问题。

【讨论】:

  • 非常感谢您抽出宝贵时间整理这些,这对我帮助很大。 :)
猜你喜欢
  • 2019-12-17
  • 2023-03-10
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-03
  • 1970-01-01
相关资源
最近更新 更多