【问题标题】:How to sort ListView.builder in decreasing order?如何按降序对 ListView.builder 进行排序?
【发布时间】:2021-07-26 07:54:02
【问题描述】:

我想按降序排列 View .builder 你能帮我吗?

List View .builder(
item Count: ..,
item Builder: (Build Context context , int i){..}
) 

【问题讨论】:

    标签: list flutter dart


    【解决方案1】:

    .sort 方法

    Flutter docs

    示例 1

    var numbers = ['two', 'three', 'four'];
    // Sort from shortest to longest.
    numbers.sort((a, b) => 
    a.length.compareTo(b.length));
    print(numbers);  // [two, four, three]
    

    示例 2

    List<int> nums = [13, 2, -11];
    nums.sort();
    print(nums);  // [-11, 2, 13]
    

    【讨论】:

      【解决方案2】:

      试试这个,这里 entries 是我的列表名称

      final List<String> entries = <String>['A','B','C'];
      
          int length = entries.length;
          return ListView.builder(
              padding: const EdgeInsets.all(8),
              itemCount: entries.length,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  height: 50,
                  child: Center(child: Text('Entry ${entries[length - 1 - index]}')),
                );
              });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-19
        • 2022-01-06
        • 1970-01-01
        • 2011-03-25
        • 1970-01-01
        • 2020-11-09
        相关资源
        最近更新 更多