yokutango-mobile-reader/lib/screens/pages/kanji_list.dart

59 lines
1.6 KiB
Dart

import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:tangocard_reader/models/data_entry.dart';
import 'package:tangocard_reader/models/router_args.dart';
import 'package:tangocard_reader/screens/misc/error.dart';
import 'package:tangocard_reader/screens/misc/loading.dart';
class KanjiList extends StatelessWidget {
final File file;
const KanjiList({
Key? key,
required this.file,
}) : super(key: key);
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(file.uri.pathSegments.last),
),
body: FutureBuilder(
future:
rootBundle.loadString(file.path).then((data) => jsonDecode(data)),
builder: (context, jsonSnapshot) {
if (jsonSnapshot.hasError) {
return const ErrorScreen();
} else if (!jsonSnapshot.hasData) {
return const LoadingScreen();
}
final entries = (jsonSnapshot.data as List)
.map((e) => KanjiEntry.fromJson(e))
.toList();
return ListView(
children: entries
.asMap()
.map(
(i, e) => MapEntry(
i,
ListTile(
title: Text(e.toString()),
onTap: () => Navigator.pushNamed(context, '/benkyou/kanji',
arguments: BenkyouArgs(cards: entries, index: i)),
),
),
)
.values
.toList(),
);
},
)
);
}