62 lines
1.8 KiB
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: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 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/tango',
|
||
|
arguments: BenkyouArgs(cards: entries, index: i),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
)
|
||
|
.values
|
||
|
.toList(),
|
||
|
);
|
||
|
},
|
||
|
));
|
||
|
}
|
||
|
}
|