listScopedImageNames function
Implementation
Future<List<String>> listScopedImageNames(String scope) async {
final s = _canonicalizeScope(scope.trim());
if (s.isEmpty || kIsWeb) return const [];
await _mergeLegacyScopeIntoCanonical(s);
final base = await localPath;
final byName = <String, DateTime>{};
void collectScope(String scopeName, {String? exposeAsScope}) {
final dir = Directory('$base/$scopeName');
if (!dir.existsSync()) return;
final outScope = exposeAsScope ?? scopeName;
for (final entity in dir.listSync(followLinks: false)) {
if (entity is! File) continue;
final segments = entity.uri.pathSegments;
if (segments.isEmpty) continue;
final filename = segments.last;
if (filename.isEmpty || filename.startsWith('.')) continue;
if (!_looksLikeImageFilename(filename)) continue;
DateTime modified = DateTime.fromMillisecondsSinceEpoch(0);
try {
modified = entity.statSync().modified;
} catch (_) {}
byName['$outScope/$filename'] = modified;
}
}
collectScope(s, exposeAsScope: s);
final legacyScope = _legacyScopeForCanonical(s);
if (legacyScope != s) {
collectScope(legacyScope, exposeAsScope: s);
}
final out = byName.keys.toList()
..sort((a, b) {
final am = byName[a] ?? DateTime.fromMillisecondsSinceEpoch(0);
final bm = byName[b] ?? DateTime.fromMillisecondsSinceEpoch(0);
final cmp = am.compareTo(bm);
return cmp != 0 ? cmp : a.compareTo(b);
});
return out;
}