我使用 Hive 和 Flutter 将联系人的键存储为字母数字字符串,每个联系人数据都是一个带有时间戳的映射
框行 =
Key. => Value
'abc123' => {'name': 'JK', 'country':'GB', 'timestamp': '568'},
'etergb' => {'name': 'FS', 'country':'DE', 'timestamp': '425'}
'546hfg' => {'name': 'TD', 'country':'GB', 'timestamp': '687'}
现在可以使用 where country=GB 条件过滤这些行并按 map.item.timestamp ASC/DESC 对行进行排序
最佳答案
过滤器
final hiveBox = Hive.box<Dynamic>('<BOX_NAME>');
List values = hiveBox.values.toList();
filtered = box.values
.where((object) => object['country'] == 'GB')
.toList();
排序
filtered.sort((a, b) => a['timestamp'].compareTo(b['timestamp']));
关于flutter - 在 Flutter 中过滤和排序来自 Hive box 的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66304606/