yokutango-mobile-reader/lib/service/tangocard_files.dart

51 lines
1.6 KiB
Dart
Raw Normal View History

2022-01-26 01:58:47 +01:00
import 'dart:convert';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:tangocard_reader/models/data_entry.dart';
// TODO: merge
Future<Map<File, List<YokutangoEntry>>> get tangocardFilePaths => rootBundle
.loadString('AssetManifest.json')
.then(
(json) => jsonDecode(json)
.keys
.where((String key) =>
key.contains('yokutango/json/') && key.contains('.json'))
.toList(),
)
.then(
(l) async => Map.fromIterables(
l.map<File>((f) => File(f)),
await Future.wait<List<YokutangoEntry>>(
l.map<Future<List<YokutangoEntry>>>(
(String t) => rootBundle.loadString(t).then<List<YokutangoEntry>>(
(s) => jsonDecode(s)
.map<YokutangoEntry>((e) => YokutangoEntry.fromJson(e))
.toList()),
)),
),
);
Future<Map<File, List<KanjiEntry>>> get kanjicardFilePaths => rootBundle
.loadString('AssetManifest.json')
.then(
(json) => jsonDecode(json)
.keys
.where((String key) =>
key.contains(RegExp(r'yokutango/kanji/kanji_\d+.json')))
.toList(),
)
.then(
(l) async => Map.fromIterables(
l.map<File>((f) => File(f)),
await Future.wait<List<KanjiEntry>>(l.map<Future<List<KanjiEntry>>>(
(String t) => rootBundle.loadString(t).then<List<KanjiEntry>>((s) =>
jsonDecode(s)
.map<KanjiEntry>((e) => KanjiEntry.fromJson(e))
.toList()),
)),
),
);