Files
cutdex/lib/shared/widgets/processing_resource_download_dialog.dart
T
lingjhf 38ca180cf7
Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
refactor(core): own editor UI and pin verified native releases
2026-10-12 03:20:29 +08:00

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),
),
),
],
),
);
}
}