gpt4 book ai didi

android - Flutter - 选定的项目移动到 ListView 的顶部

转载 作者:IT王子 更新时间:2023-10-29 06:55:03 25 4
gpt4 key购买 nike

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

这可以通过按下 ListView 元素旁边的 iconbutton 来实现,并让该元素在 refresh 时移动到顶部。

如果可能的话,我希望图标按钮在启用时变为启用(即发光/点亮),并且禁用(变灰,但仍按-able)禁用时。

我无法将我的所有代码都包含在这个问题中,所以所有这些连同 _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);
                },
              ),
            ),
          ],
        )
      );
  }

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

最佳答案

这听起来很像一个类项目,所以我将为您指明正确的方向,让您自己解决这个问题。

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

当 _currencies 列表更改时,您如何让 _cryptoWidget 重绘? 您会使用有状态小部件还是无状态小部件?当数据改变时,其中哪一个会重绘自己?

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

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

关于android - Flutter - 选定的项目移动到 ListView 的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51459845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com