Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
130 lines
3.9 KiB
Dart
130 lines
3.9 KiB
Dart
import 'package:cutdex/l10n/l10n.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cutdex_ui/theme.dart';
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
|
|
/// Shared layout for downloading a processing resource before a task starts.
|
|
class ProcessingResourceDownloadDialog extends StatelessWidget {
|
|
const ProcessingResourceDownloadDialog({
|
|
super.key,
|
|
required this.title,
|
|
required this.description,
|
|
required this.resourceName,
|
|
required this.downloadSize,
|
|
required this.downloading,
|
|
required this.paused,
|
|
required this.downloadedBytes,
|
|
required this.totalBytes,
|
|
required this.bytesPerSecond,
|
|
required this.onCancel,
|
|
required this.onDownload,
|
|
required this.onTogglePause,
|
|
required this.onBackground,
|
|
this.error,
|
|
this.downloadButtonKey,
|
|
this.pauseButtonKey,
|
|
this.backgroundButtonKey,
|
|
});
|
|
|
|
final String title;
|
|
final String description;
|
|
final String resourceName;
|
|
final String downloadSize;
|
|
final bool downloading;
|
|
final bool paused;
|
|
final int downloadedBytes;
|
|
final int totalBytes;
|
|
final int bytesPerSecond;
|
|
final VoidCallback onCancel;
|
|
final VoidCallback onDownload;
|
|
final VoidCallback onTogglePause;
|
|
final VoidCallback onBackground;
|
|
final String? error;
|
|
final Key? downloadButtonKey;
|
|
final Key? pauseButtonKey;
|
|
final Key? backgroundButtonKey;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final percentage = totalBytes <= 0
|
|
? 0
|
|
: (downloadedBytes * 100 / totalBytes).floor().clamp(0, 100);
|
|
return AppDialog(
|
|
title: title,
|
|
description: description,
|
|
width: 440,
|
|
closeLabel: downloading ? context.l10n.downloadInBackground : null,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: onCancel,
|
|
child: Text(
|
|
downloading ? context.l10n.cancelDownload : context.l10n.cancel,
|
|
),
|
|
),
|
|
if (downloading)
|
|
TextButton(
|
|
key: pauseButtonKey,
|
|
onPressed: onTogglePause,
|
|
child: Text(
|
|
paused ? context.l10n.resumeDownload : context.l10n.pauseDownload,
|
|
),
|
|
),
|
|
FilledButton(
|
|
key: downloading ? backgroundButtonKey : downloadButtonKey,
|
|
onPressed: downloading ? onBackground : onDownload,
|
|
child: Text(
|
|
downloading
|
|
? context.l10n.downloadInBackground
|
|
: context.l10n.downloadModelAction,
|
|
),
|
|
),
|
|
],
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
if (!downloading) Text(downloadSize),
|
|
if (downloading) ...[
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
resourceName,
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
paused ? context.l10n.downloadPaused : '$percentage%',
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: AppSpacing.small),
|
|
ResourceDownloadProgress(
|
|
downloadedBytes: downloadedBytes,
|
|
totalBytes: totalBytes,
|
|
bytesPerSecond: bytesPerSecond,
|
|
status: '',
|
|
paused: paused,
|
|
),
|
|
],
|
|
if (error != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: AppSpacing.compact),
|
|
child: Text(
|
|
error!,
|
|
style: TextStyle(color: theme.colorScheme.error),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|