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

60 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:tangocard_reader/models/router_args.dart';
import 'package:tangocard_reader/models/yokutango_entry.dart';
import 'package:tangocard_reader/screens/error.dart';
import 'package:tangocard_reader/screens/loading.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class TangoList extends StatelessWidget {
final File file;
const TangoList({
required this.file,
Key? key,
}) : super(key: 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',
arguments: BenkyouArgs(cards: entries, index: i)),
),
),
)
.values
.toList(),
);
},
),
);
}
}