64 lines
2.0 KiB
Dart
64 lines
2.0 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:yokutango_mobile_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) {
|
|
final jsonKeys = jsonDecode(json).keys;
|
|
|
|
final kanjiPaths = jsonKeys
|
|
.where((String key) =>
|
|
RegExp(r'assets/yokutango/kanji/kanji_\d+.json')
|
|
.matchAsPrefix(key) !=
|
|
null)
|
|
.toList();
|
|
|
|
final kanaPaths = jsonKeys
|
|
.where((String key) =>
|
|
RegExp(r'assets/yokutango/kanji/(?:hiragana|katakana).json')
|
|
.matchAsPrefix(key) !=
|
|
null)
|
|
.toList();
|
|
|
|
return kanaPaths + kanjiPaths;
|
|
},
|
|
).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()),
|
|
)),
|
|
),
|
|
);
|