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'; class DownloadsScreen extends StatefulWidget { const DownloadsScreen({super.key}); @override State createState() => _DownloadsScreenState(); } class _DownloadsScreenState extends State { @override Widget build(BuildContext context) { return FutureBuilder( future: client.query$ListTorrents(), builder: (context, snapshot) { if (!snapshot.hasData || snapshot.data == null) { return const Center(child: CircularProgressIndicator()); } final torrents = snapshot.data!.parsedData!.torrents; return ListView.builder( itemCount: torrents.length, itemBuilder: (context, index) { final torrent = torrents[index]; return ListTile( title: Text(torrent.name), subtitle: DownloadProgress( torrent.bytesCompleted, torrent.bytesCompleted + torrent.bytesMissing), 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), ) ], ), ); }, ); }, ); } }