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

62 lines
1.8 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';
import 'package:yokutango_mobile_reader/models/router_args.dart';
import 'package:yokutango_mobile_reader/screens/misc/error.dart';
import 'package:yokutango_mobile_reader/screens/misc/loading.dart';
class TangoList extends StatelessWidget {
final File file;
const TangoList({
required this.file,
super.key,
});
@override
Widget build(BuildContext context) {
return 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) => YokutangoEntry.fromJson(e))
.toList();
return ListView(
children: entries
.asMap()
.map(
(i, e) => MapEntry(
i,
ListTile(
title: Text(e.toString()),
onTap: () => Navigator.pushNamed(
context,
'/benkyou/tango',
arguments: BenkyouArgs(cards: entries, index: i),
),
),
),
)
.values
.toList(),
);
},
));
}
}