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

59 lines
1.6 KiB
Dart
Raw Normal View History

2022-01-26 00:25:07 +01:00
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2022-01-26 01:58:47 +01:00
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';
2022-01-26 00:25:07 +01:00
2022-01-26 01:58:47 +01:00
class KanjiList extends StatelessWidget {
2022-01-26 00:25:07 +01:00
final File file;
2022-01-26 01:58:47 +01:00
const KanjiList({
2022-01-26 00:25:07 +01:00
Key? key,
2022-01-26 01:58:47 +01:00
required this.file,
2022-01-26 00:25:07 +01:00
}) : super(key: key);
@override
2022-01-26 01:58:47 +01:00
Widget build(BuildContext context) => Scaffold(
2022-01-26 00:25:07 +01:00
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)
2022-01-26 01:58:47 +01:00
.map((e) => KanjiEntry.fromJson(e))
2022-01-26 00:25:07 +01:00
.toList();
return ListView(
children: entries
.asMap()
.map(
(i, e) => MapEntry(
i,
ListTile(
title: Text(e.toString()),
2022-01-26 01:58:47 +01:00
onTap: () => Navigator.pushNamed(context, '/benkyou/kanji',
2022-01-26 00:25:07 +01:00
arguments: BenkyouArgs(cards: entries, index: i)),
),
),
)
.values
.toList(),
);
},
2022-01-26 01:58:47 +01:00
)
2022-01-26 00:25:07 +01:00
);
2022-01-26 01:58:47 +01:00
2022-01-26 00:25:07 +01:00
}