tstor/ui/lib/screens/downloads.dart
royalcat 0d7aac068c
All checks were successful
docker / build-docker (linux/amd64) (push) Successful in 1m39s
docker / build-docker (linux/386) (push) Successful in 1m46s
docker / build-docker (linux/arm64/v8) (push) Successful in 8m18s
docker / build-docker (linux/arm64) (push) Successful in 8m29s
docker / build-docker (linux/arm/v7) (push) Successful in 8m49s
torrent list
2024-04-27 14:00:34 +03:00

109 lines
3.2 KiB
Dart

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';
import 'package:tstor_ui/components/sliver_header.dart';
class DownloadsScreen extends StatefulWidget {
const DownloadsScreen({super.key});
@override
State<DownloadsScreen> createState() => _DownloadsScreenState();
}
class _DownloadsScreenState extends State<DownloadsScreen> {
bool filterDownloading = false;
@override
Widget build(BuildContext context) {
return FutureBuilder(
key: GlobalKey(),
future: client.query$ListTorrents(Options$Query$ListTorrents(
variables: Variables$Query$ListTorrents(downloading: filterDownloading),
)),
builder: (context, snapshot) {
final torrents = snapshot.data?.parsedData?.torrents;
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;
}),
),
],
),
),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => setState(() {}),
),
],
),
],
body: snapshot.hasData && torrents != null
? ListView.builder(
itemCount: torrents.length,
itemBuilder: (context, index) => TorrentTile(torrent: torrents[index]),
)
: const Center(child: CircularProgressIndicator()),
);
},
);
}
}
class TorrentTile extends StatelessWidget {
final Query$ListTorrents$torrents torrent;
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),
)
],
),
);
}
}