【问题标题】:Order SliverList in Flutter在 Flutter 中订购 SliverList
【发布时间】:2019-12-24 00:52:25
【问题描述】:

我有这个小部件:

body: CustomScrollView(
              slivers: <Widget>[
                SliverList(
                  delegate: SliverChildBuilderDelegate(
                      (BuildContext context, int index) {
                    return _team(context, index);
                  }, childCount: Provider.of<Game>(context).teams.list.length),
                ),
              ],
            ),

这里我显示了一个带有int 属性的对象数组(或地图列表)。

如何在不修改变量本身的情况下按此排序我的数组?

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    您可以使用以下函数获取一个局部变量并将其随机化并可以使用它。

    List shuffle(List items) {
      var random = new Random();
    
      // Go through all elements.
      for (var i = items.length - 1; i > 0; i--) {
    
        // Pick a pseudorandom number according to the list length
        var n = random.nextInt(i + 1);
    
        var temp = items[i];
        items[i] = items[n];
        items[n] = temp;
      }
    
      return items;
    }
    

    【讨论】:

    • 对不起,我完全不明白你的问题。我想随机化它做什么?
    猜你喜欢
    • 2020-07-10
    • 2020-01-28
    • 2021-01-22
    • 2018-10-26
    • 2021-04-17
    • 2021-10-20
    • 2021-10-18
    • 2021-06-02
    相关资源
    最近更新 更多