tstor/ui/lib/screens/downloads.dart

112 lines
3.4 KiB
Dart
Raw Normal View History

2024-04-24 17:36:33 +00:00
import 'package:flutter/material.dart';
import 'package:tstor_ui/api/client.dart';
import 'package:tstor_ui/api/torrent.graphql.dart';
import 'package:tstor_ui/components/download.dart';
2024-04-27 11:00:34 +00:00
import 'package:tstor_ui/components/sliver_header.dart';
2024-04-24 17:36:33 +00:00
class DownloadsScreen extends StatefulWidget {
const DownloadsScreen({super.key});
@override
State<DownloadsScreen> createState() => _DownloadsScreenState();
}
class _DownloadsScreenState extends State<DownloadsScreen> {
2024-04-27 11:00:34 +00:00
bool filterDownloading = false;
2024-04-24 17:36:33 +00:00
@override
Widget build(BuildContext context) {
2024-05-13 16:56:20 +00:00
return SafeArea(
child: FutureBuilder(
key: GlobalKey(),
future: client.query$ListTorrents(Options$Query$ListTorrents(
2024-08-15 08:23:44 +00:00
// variables: Variables$Query$ListTorrents(downloading: filterDownloading),
)),
2024-05-13 16:56:20 +00:00
builder: (context, snapshot) {
2024-08-15 08:23:44 +00:00
final torrents = snapshot.data?.parsedData?.torrentDaemon?.torrents;
2024-04-27 11:00:34 +00:00
2024-05-13 16:56:20 +00:00
return NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (context, innerBoxIsScrolled) => [
HideableHeaderSliver(
height: 80,
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
spacing: 8,
runSpacing: 8,
children: [
FilterChip(
label: const Text("Downloading"),
selected: filterDownloading,
onSelected: (value) => setState(() {
filterDownloading = value;
}),
),
],
),
2024-04-27 11:00:34 +00:00
),
2024-05-13 16:56:20 +00:00
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => setState(() {}),
),
],
2024-04-24 17:36:33 +00:00
),
2024-05-13 16:56:20 +00:00
],
body: snapshot.hasData && torrents != null
? ListView.builder(
itemCount: torrents.length,
itemBuilder: (context, index) => TorrentTile(torrent: torrents[index]),
)
: const Center(child: CircularProgressIndicator()),
);
},
),
2024-04-24 17:36:33 +00:00
);
}
}
2024-04-27 11:00:34 +00:00
class TorrentTile extends StatelessWidget {
2024-08-15 08:23:44 +00:00
final Query$ListTorrents$torrentDaemon$torrents torrent;
2024-04-27 11:00:34 +00:00
const TorrentTile({super.key, required this.torrent});
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(torrent.name),
isThreeLine: true,
subtitle: Column(
children: [
DownloadProgress(
torrent.bytesCompleted,
torrent.bytesCompleted + torrent.bytesMissing,
),
Row(
children: [
Text("Peers: ${torrent.peers.length}"),
],
),
],
),
trailing: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () => client.mutate$MarkTorrentDownload(
Options$Mutation$MarkTorrentDownload(
variables: Variables$Mutation$MarkTorrentDownload(
infohash: torrent.infohash,
),
),
),
icon: const Icon(Icons.download),
)
],
),
);
}
}