Add kanji page
This commit is contained in:
50
lib/service/tangocard_files.dart
Normal file
50
lib/service/tangocard_files.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
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()),
|
||||
)),
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user