mhunt_launcher/lib/Widgets/Home/Downloads.dart
2024-10-28 17:34:48 +05:30

129 lines
4.4 KiB
Dart

import 'package:flutter/material.dart';
import '../../Backend/Backend.dart';
import '../../Backend/FileHashEntry.dart';
import '../CustomWidgets.dart';
Widget DownloadCard({
required int gameId,
required Map<int, Map<FileHashEntry, num>> downloadProgress,
required Map<int, double> totalDownloadSize,
required Map<int, List<FileHashEntry>> downloadQueue,
required bool downloadRunning,
required Function(int) onChanged
}) {
int doneSize = 0;
if (downloadProgress.containsKey(gameId)) {
Map<FileHashEntry, num> _progress = downloadProgress[gameId]!;
_progress.forEach((key, value) {
doneSize += value.toInt();
});
}
double totalSize = totalDownloadSize[gameId]! / 1024 / 1024;
double doneSizeMb = doneSize / 1024 / 1024;
double progress = doneSizeMb / totalSize;
return Padding(
padding: const EdgeInsets.all(8.0),
child: GlassCard(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image:
AssetImage(Backend.Games[gameId].imagePath)),
borderRadius: BorderRadius.circular(50)),
width: 160,
height: 80,
),
Column(
children: [
Text(
Backend.Games[gameId].name,
style: TextStyle(fontSize: 20),
),
Text((doneSizeMb).toStringAsFixed(2) +
" MB" +
" / " +
totalSize.toStringAsFixed(2) +
" MB")
],
)
],
),
Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(20, 50, 20, 20),
child: LinearProgressIndicator(
value: progress,
backgroundColor: Colors.black.withOpacity(0.2),
color: Colors.blue,
),
),
),
InkWell(
child: Icon(Icons.cancel,
size: 40, color: Colors.red.withOpacity(0.6)),
onTap: () {
downloadQueue.remove(gameId);
downloadProgress.remove(gameId);
downloadRunning = false;
onChanged(gameId);
},
)
// Icon(Icons.download,size: 40,color: Colors.green.withOpacity(0.4),)
],
)
],
),
)),
);
}
Widget Downloads({
required Map<int, List<FileHashEntry>> downloadQueue,
required Map<int, Map<FileHashEntry, num>> downloadProgress,
required Map<int, double> totalDownloadSize,
required bool downloadRunning,
required Function(int) onChanged
}) {
if (downloadQueue.length <= 0) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.download_done_sharp,
size: 100,
color: Colors.white.withOpacity(0.5),
),
Text(
"No ongoing Downloads",
style:
TextStyle(fontSize: 40, color: Colors.white.withOpacity(0.4)),
),
],
),
);
}
return Container(
child: Container(
padding: EdgeInsets.all(100),
child: GlassCard(
child: Column(
children: List.generate(downloadQueue.keys.length, (index) {
int gameId = downloadQueue.keys.toList()[index];
return DownloadCard(gameId: gameId, downloadQueue:downloadQueue, downloadProgress: downloadProgress, downloadRunning: downloadRunning, totalDownloadSize: totalDownloadSize, onChanged: onChanged );
}),
))));
}