相关疑难解决方法(0)

在 Dart 中按键或按值对地图进行排序

我有以下地图

Map testMap = { 
  3 : {
    'order': 3,
    'sample' : 'sample'
  },
  2 : {
    'order': 2,
    'sample' : 'sample'
  },
  1 : {
    'order': 1,
    'sample' : 'sample'
  },
  4: {
    'order': 4,
    'sample' : 'sample'
  }
};
Run Code Online (Sandbox Code Playgroud)

如果不可能通过子映射内的“顺序”值,我如何按键对其进行排序。

注意:地图最多可容纳 100 个字段。

解决了 我之前一定很累了,但以防万一其他人正在看这里是我的解决方案。另外,仅通过按键排序会SplayTreeMap产生奇怪的顺序,例如 1,10,11,12,13,14,15,16,17,18,19,2,20,21 ...

import 'dart:collection';

void main() {
  Map testMap = {
     11: {
      'order': '11',
      'sample' : 'sample'
    },
    3 : {
      'order': '3',
      'sample' : 'sample'
    },
    2 : { …
Run Code Online (Sandbox Code Playgroud)

dart

9
推荐指数
2
解决办法
9681
查看次数

如何在 dart/Flutter 中使用 Firebase 快照字典上的 SplayTreeMap?

我已成功通过 StreamBuilder 取回数据并需要对其进行排序。如何按键对快照数据的映射进行排序?另外,如果你给出一个这样做的例子,我的价值也会有所帮助。我想我想做一个 SplayTreeMap,但如果有更好的方法请提供。这是我的字典...

\n\n
{Vid2: {imageString: https://i.ytimg.com/vi/Amq-qlqbjYA/mqdefault.jpg, title: BLACKPINK - \'\xeb\xa7\x88\xec\xa7\x80\xeb\xa7\x89\xec\xb2\x98\xeb\x9f\xbc (AS IF IT\'S YOUR LAST)\' M/V, rank: 2, videoID: Amq-qlqbjYA}, Vid10: {imageString: https://i.ytimg.com/vi/KSH-FVVtTf0/mqdefault.jpg, title: EXO \xec\x97\x91\xec\x86\x8c \'Monster\' MV, rank: 10, videoID: KSH-FVVtTf0}, Vid6: {imageString: https://i.ytimg.com/vi/BVwAVbKYYeM/mqdefault.jpg, title: [MV] BTS(\xeb\xb0\xa9\xed\x83\x84\xec\x86\x8c\xeb\x85\x84\xeb\x8b\xa8) _ DOPE(\xec\xa9\x94\xec\x96\xb4), rank: 6, videoID: BVwAVbKYYeM}, Vid3: {imageString: https://i.ytimg.com/vi/m8MfJg68oCs/mqdefault.jpg, title: [MV] BTS(\xeb\xb0\xa9\xed\x83\x84\xec\x86\x8c\xeb\x85\x84\xeb\x8b\xa8) _ Boy In Luv(\xec\x83\x81\xeb\x82\xa8\xec\x9e\x90), rank: 3, videoID: m8MfJg68oCs}, Vid4: {imageString: https://i.ytimg.com/vi/9pdj4iJD08s/mqdefault.jpg, title: BLACKPINK - \'\xeb\xb6\x88\xec\x9e\xa5\xeb\x82\x9c (PLAYING WITH FIRE)\' M/V, rank: 4, videoID: 9pdj4iJD08s}, Vid1: {imageString: https://i.ytimg.com/vi/3s1jaFDrp5M/mqdefault.jpg, title: EPIK …
Run Code Online (Sandbox Code Playgroud)

sorting dictionary splay-tree dart flutter

4
推荐指数
1
解决办法
4327
查看次数

如何在 Dart 中对 MappedListIterable 进行排序

我有一个MappedListIterable比我知道的要排序的

调用排序方法时,我得到

例外:NoSuchMethodError:类“MappedListIterable”没有实例方法“sort”。接收器:'MappedListIterable' 的实例尝试调用:sort(Closure: (dynamic, dynamic) => dynamic)

dart dart-html

1
推荐指数
1
解决办法
3818
查看次数

标签 统计

dart ×3

dart-html ×1

dictionary ×1

flutter ×1

sorting ×1

splay-tree ×1