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>> 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((f) => File(f)), await Future.wait>( l.map>>( (String t) => rootBundle.loadString(t).then>( (s) => jsonDecode(s) .map((e) => YokutangoEntry.fromJson(e)) .toList()), )), ), ); Future>> 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((f) => File(f)), await Future.wait>(l.map>>( (String t) => rootBundle.loadString(t).then>((s) => jsonDecode(s) .map((e) => KanjiEntry.fromJson(e)) .toList()), )), ), );