Vaani/lib/features/downloads/view/downloads_page.dart

51 lines
1.7 KiB
Dart
Raw Normal View History

2024-08-20 08:36:39 -04:00
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
2024-08-23 04:21:46 -04:00
import 'package:vaani/features/downloads/providers/download_manager.dart';
2024-08-20 08:36:39 -04:00
class DownloadsPage extends HookConsumerWidget {
const DownloadsPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final manager = ref.read(simpleDownloadManagerProvider);
final downloadHistory = ref.watch(downloadHistoryProvider());
return Scaffold(
appBar: AppBar(
title: const Text('Downloads'),
),
body: Center(
// history of downloads
child: downloadHistory.when(
data: (records) {
// each group is one list tile, which contains the files downloaded
final uniqueGroups = records.map((e) => e.group).toSet();
return ListView.builder(
itemCount: uniqueGroups.length,
itemBuilder: (context, index) {
final group = uniqueGroups.elementAt(index);
final groupRecords = records.where((e) => e.group == group);
return ExpansionTile(
title: Text(group ?? 'No Group'),
children: groupRecords
.map(
(e) => ListTile(
title: Text('${e.task.directory}/${e.task.filename}'),
subtitle: Text(e.task.creationTime.toString()),
),
)
.toList(),
);
},
);
},
loading: () => const CircularProgressIndicator(),
error: (error, stackTrace) {
return Text('Error: $error');
},
),
),
);
}
}