mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 14:23:42 +00:00
feat: new ui (#1455)
This commit is contained in:
742 files changed
+59951
-5934
No files matched your search
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../../../core/utils/breakpoints.dart';
|
||||
import '../../../domain/task_record.dart';
|
||||
import '../task_context_menu.dart';
|
||||
import 'task_card_desktop.dart';
|
||||
import 'task_card_mobile.dart';
|
||||
|
||||
class TaskCard extends StatelessWidget {
|
||||
const TaskCard({
|
||||
super.key,
|
||||
required this.task,
|
||||
required this.selected,
|
||||
required this.batchMode,
|
||||
required this.selectedInBatch,
|
||||
required this.onPressed,
|
||||
required this.onToggleBatch,
|
||||
this.onPause,
|
||||
this.onResume,
|
||||
this.onDelete,
|
||||
this.onOpen,
|
||||
this.onReveal,
|
||||
this.contextActions,
|
||||
this.listeningForUpdate = false,
|
||||
});
|
||||
|
||||
final TaskRecord task;
|
||||
final bool selected;
|
||||
final bool batchMode;
|
||||
final bool selectedInBatch;
|
||||
final VoidCallback onPressed;
|
||||
final VoidCallback onToggleBatch;
|
||||
final VoidCallback? onPause;
|
||||
final VoidCallback? onResume;
|
||||
final VoidCallback? onDelete;
|
||||
final VoidCallback? onOpen;
|
||||
final VoidCallback? onReveal;
|
||||
final TaskContextActions? contextActions;
|
||||
final bool listeningForUpdate;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isMobile = MediaQuery.sizeOf(context).width < Breakpoints.mobile;
|
||||
|
||||
if (isMobile) {
|
||||
final card = TaskCardMobile(
|
||||
task: task,
|
||||
selected: selected,
|
||||
batchMode: batchMode,
|
||||
selectedInBatch: selectedInBatch,
|
||||
onPressed: onPressed,
|
||||
onToggleBatch: onToggleBatch,
|
||||
onPause: onPause,
|
||||
onResume: onResume,
|
||||
onDelete: onDelete,
|
||||
onOpen: onOpen,
|
||||
onReveal: onReveal,
|
||||
listeningForUpdate: listeningForUpdate,
|
||||
);
|
||||
final actions = contextActions;
|
||||
return actions == null ? card : TaskContextMenu(task: task, actions: actions, child: card);
|
||||
}
|
||||
|
||||
final card = TaskCardDesktop(
|
||||
task: task,
|
||||
selected: selected,
|
||||
batchMode: batchMode,
|
||||
selectedInBatch: selectedInBatch,
|
||||
onPressed: onPressed,
|
||||
onToggleBatch: onToggleBatch,
|
||||
onPause: onPause,
|
||||
onResume: onResume,
|
||||
onDelete: onDelete,
|
||||
onOpen: onOpen,
|
||||
onReveal: onReveal,
|
||||
listeningForUpdate: listeningForUpdate,
|
||||
);
|
||||
final actions = contextActions;
|
||||
return actions == null ? card : TaskContextMenu(task: task, actions: actions, child: card);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
import 'package:flutter/gestures.dart' show TapUpDetails, kDoubleTapSlop, kDoubleTapTimeout;
|
||||
import 'package:flutter/material.dart' show Colors, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../../../shared/theme/app_design_tokens.dart';
|
||||
import '../../../../../shared/theme/app_palette.dart';
|
||||
import '../../../domain/task_record.dart';
|
||||
import '../task_progress_bar.dart';
|
||||
import 'task_card_parts.dart';
|
||||
|
||||
class TaskCardDesktop extends StatefulWidget {
|
||||
const TaskCardDesktop({
|
||||
super.key,
|
||||
required this.task,
|
||||
required this.selected,
|
||||
required this.batchMode,
|
||||
required this.selectedInBatch,
|
||||
required this.onPressed,
|
||||
required this.onToggleBatch,
|
||||
this.onPause,
|
||||
this.onResume,
|
||||
this.onDelete,
|
||||
this.onOpen,
|
||||
this.onReveal,
|
||||
this.listeningForUpdate = false,
|
||||
});
|
||||
|
||||
final TaskRecord task;
|
||||
final bool selected;
|
||||
final bool batchMode;
|
||||
final bool selectedInBatch;
|
||||
final VoidCallback onPressed;
|
||||
final VoidCallback onToggleBatch;
|
||||
final VoidCallback? onPause;
|
||||
final VoidCallback? onResume;
|
||||
final VoidCallback? onDelete;
|
||||
final VoidCallback? onOpen;
|
||||
final VoidCallback? onReveal;
|
||||
final bool listeningForUpdate;
|
||||
|
||||
@override
|
||||
State<TaskCardDesktop> createState() => _TaskCardDesktopState();
|
||||
}
|
||||
|
||||
class _TaskCardDesktopState extends State<TaskCardDesktop> {
|
||||
bool _hovered = false;
|
||||
DateTime? _lastTapTime;
|
||||
Offset? _lastTapPosition;
|
||||
|
||||
void _handleTap(TapUpDetails details) {
|
||||
final now = DateTime.now();
|
||||
final lastTapTime = _lastTapTime;
|
||||
final lastTapPosition = _lastTapPosition;
|
||||
final isDoubleTap =
|
||||
!widget.batchMode &&
|
||||
widget.task.status == TaskStatus.completed &&
|
||||
lastTapTime != null &&
|
||||
now.difference(lastTapTime) <= kDoubleTapTimeout &&
|
||||
lastTapPosition != null &&
|
||||
(details.globalPosition - lastTapPosition).distance <= kDoubleTapSlop;
|
||||
|
||||
_lastTapTime = isDoubleTap ? null : now;
|
||||
_lastTapPosition = isDoubleTap ? null : details.globalPosition;
|
||||
widget.onPressed();
|
||||
if (isDoubleTap) {
|
||||
widget.onOpen?.call();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final task = widget.task;
|
||||
final isDark = shad.Theme.of(context).brightness == Brightness.dark;
|
||||
final isError = task.status == TaskStatus.failed;
|
||||
final borderColor = isDark ? palette.border : palette.border.withValues(alpha: 0.6);
|
||||
final baseColor = isDark ? palette.cardBg : palette.cardBg.withValues(alpha: 0.92);
|
||||
final hoverColor = palette.taskCardHoverBg;
|
||||
final radius = BorderRadius.circular(AppDesignTokens.controlRadius);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
onTapUp: _handleTap,
|
||||
child: Container(
|
||||
height: AppDesignTokens.taskRowHeight,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: radius,
|
||||
boxShadow: widget.selected
|
||||
? [BoxShadow(color: palette.taskCardSelectedBorder, blurRadius: 0, spreadRadius: 1)]
|
||||
: null,
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: radius,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
ColoredBox(color: baseColor),
|
||||
if (_hovered)
|
||||
IgnorePointer(
|
||||
child: ColoredBox(key: const ValueKey('task-card-hover-surface'), color: hoverColor),
|
||||
),
|
||||
IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: radius,
|
||||
border: Border.all(color: _hovered ? palette.border : borderColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 13),
|
||||
child: Row(
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 220),
|
||||
width: widget.batchMode ? 36 : 0,
|
||||
child: widget.batchMode
|
||||
? Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: shad.Checkbox(
|
||||
state: widget.selectedInBatch
|
||||
? shad.CheckboxState.checked
|
||||
: shad.CheckboxState.unchecked,
|
||||
onChanged: (_) => widget.onToggleBatch(),
|
||||
borderColor: palette.border,
|
||||
backgroundColor: palette.cardBg,
|
||||
size: 20,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
TaskCardIcon(task: task),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 46,
|
||||
child: task.status == TaskStatus.completed
|
||||
? _CompletedContent(
|
||||
task: task,
|
||||
isDark: isDark,
|
||||
onReveal: widget.onReveal,
|
||||
onDelete: widget.onDelete,
|
||||
listeningForUpdate: widget.listeningForUpdate,
|
||||
)
|
||||
: _ProgressContent(
|
||||
task: task,
|
||||
isError: isError,
|
||||
isDark: isDark,
|
||||
onPause: widget.onPause,
|
||||
onResume: widget.onResume,
|
||||
onDelete: widget.onDelete,
|
||||
listeningForUpdate: widget.listeningForUpdate,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProgressContent extends StatelessWidget {
|
||||
const _ProgressContent({
|
||||
required this.task,
|
||||
required this.isError,
|
||||
required this.isDark,
|
||||
this.onPause,
|
||||
this.onResume,
|
||||
this.onDelete,
|
||||
required this.listeningForUpdate,
|
||||
});
|
||||
|
||||
final TaskRecord task;
|
||||
final bool isError;
|
||||
final bool isDark;
|
||||
final VoidCallback? onPause;
|
||||
final VoidCallback? onResume;
|
||||
final VoidCallback? onDelete;
|
||||
final bool listeningForUpdate;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final fillColor = taskCardFillColor(palette, task.status, isDark);
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 21,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 14, fontWeight: FontWeight.w500, height: 1),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
if (listeningForUpdate) ...[const TaskUpdateListeningIndicator(), const SizedBox(width: 8)],
|
||||
Row(mainAxisSize: MainAxisSize.min, children: _buildActionButtons(task, palette, isDark)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
TaskProgressBar(
|
||||
value: task.progress,
|
||||
indeterminate: task.isIndeterminate,
|
||||
trackColor: palette.brandTrack,
|
||||
fillColor: fillColor,
|
||||
highlightStartColor: fillColor,
|
||||
highlightEndColor: fillColor,
|
||||
shimmer: task.status == TaskStatus.downloading,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
TaskCardFooter(task: task, isError: isError),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildActionButtons(TaskRecord task, AppPalette palette, bool isDark) {
|
||||
final actions = switch (task.status) {
|
||||
TaskStatus.downloading => [(Icons.pause, onPause), (Icons.close, onDelete)],
|
||||
TaskStatus.paused => [(Icons.play_arrow, onResume), (Icons.close, onDelete)],
|
||||
TaskStatus.failed => [(Icons.refresh, onResume), (Icons.delete_outline, onDelete)],
|
||||
TaskStatus.completed => [(Icons.folder_open_outlined, null), (Icons.delete_outline, onDelete)],
|
||||
};
|
||||
|
||||
return actions
|
||||
.map(
|
||||
(action) => TaskCardActionButton(
|
||||
icon: action.$1,
|
||||
color: palette.taskCardAction,
|
||||
onPressed: action.$2 ?? () {},
|
||||
hoverBackground: isDark ? palette.border : Colors.transparent,
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
}
|
||||
}
|
||||
|
||||
class _CompletedContent extends StatelessWidget {
|
||||
const _CompletedContent({
|
||||
required this.task,
|
||||
required this.isDark,
|
||||
required this.listeningForUpdate,
|
||||
this.onReveal,
|
||||
this.onDelete,
|
||||
});
|
||||
|
||||
final TaskRecord task;
|
||||
final bool isDark;
|
||||
final VoidCallback? onReveal;
|
||||
final VoidCallback? onDelete;
|
||||
final bool listeningForUpdate;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 21,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 14, fontWeight: FontWeight.w500, height: 1),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
if (listeningForUpdate) ...[const TaskUpdateListeningIndicator(), const SizedBox(width: 8)],
|
||||
Row(mainAxisSize: MainAxisSize.min, children: _buildActionButtons(task, palette, isDark)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
TaskCardCompletedMeta(task: task),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildActionButtons(TaskRecord task, AppPalette palette, bool isDark) {
|
||||
final actions = switch (task.status) {
|
||||
TaskStatus.downloading => [(Icons.pause, null), (Icons.close, onDelete)],
|
||||
TaskStatus.paused => [(Icons.play_arrow, null), (Icons.close, onDelete)],
|
||||
TaskStatus.failed => [(Icons.refresh, null), (Icons.delete_outline, onDelete)],
|
||||
TaskStatus.completed => [(Icons.folder_open_outlined, onReveal), (Icons.delete_outline, onDelete)],
|
||||
};
|
||||
|
||||
return actions
|
||||
.map(
|
||||
(action) => TaskCardActionButton(
|
||||
icon: action.$1,
|
||||
color: palette.taskCardAction,
|
||||
onPressed: action.$2 ?? () {},
|
||||
hoverBackground: isDark ? palette.border : Colors.transparent,
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
import 'package:flutter/material.dart' show Colors, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../../../shared/theme/app_design_tokens.dart';
|
||||
import '../../../../../shared/theme/app_palette.dart';
|
||||
import '../../../domain/task_record.dart';
|
||||
import '../task_progress_bar.dart';
|
||||
import 'task_card_parts.dart';
|
||||
|
||||
class TaskCardMobile extends StatefulWidget {
|
||||
const TaskCardMobile({
|
||||
super.key,
|
||||
required this.task,
|
||||
required this.selected,
|
||||
required this.batchMode,
|
||||
required this.selectedInBatch,
|
||||
required this.onPressed,
|
||||
required this.onToggleBatch,
|
||||
this.onPause,
|
||||
this.onResume,
|
||||
this.onDelete,
|
||||
this.onOpen,
|
||||
this.onReveal,
|
||||
this.listeningForUpdate = false,
|
||||
});
|
||||
|
||||
final TaskRecord task;
|
||||
final bool selected;
|
||||
final bool batchMode;
|
||||
final bool selectedInBatch;
|
||||
final VoidCallback onPressed;
|
||||
final VoidCallback onToggleBatch;
|
||||
final VoidCallback? onPause;
|
||||
final VoidCallback? onResume;
|
||||
final VoidCallback? onDelete;
|
||||
final VoidCallback? onOpen;
|
||||
final VoidCallback? onReveal;
|
||||
final bool listeningForUpdate;
|
||||
|
||||
@override
|
||||
State<TaskCardMobile> createState() => _TaskCardMobileState();
|
||||
}
|
||||
|
||||
class _TaskCardMobileState extends State<TaskCardMobile> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final isDark = shad.Theme.of(context).brightness == Brightness.dark;
|
||||
final borderColor = isDark ? palette.border : palette.border.withValues(alpha: 0.6);
|
||||
final baseColor = isDark ? palette.cardBg : palette.cardBg.withValues(alpha: 0.92);
|
||||
final hoverColor = palette.taskCardHoverBg;
|
||||
final radius = BorderRadius.circular(AppDesignTokens.controlRadius);
|
||||
final task = widget.task;
|
||||
final fillColor = taskCardFillColor(palette, task.status, isDark);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.onPressed,
|
||||
onDoubleTap: !widget.batchMode && task.status == TaskStatus.completed ? widget.onOpen : null,
|
||||
child: Container(
|
||||
key: const ValueKey('task-card-mobile-surface'),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: radius,
|
||||
boxShadow: widget.selected
|
||||
? [BoxShadow(color: palette.taskCardSelectedBorder, blurRadius: 0, spreadRadius: 1)]
|
||||
: null,
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: radius,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(child: ColoredBox(color: baseColor)),
|
||||
if (_hovered)
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: ColoredBox(key: const ValueKey('task-card-hover-surface'), color: hoverColor),
|
||||
),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: radius,
|
||||
border: Border.all(color: _hovered ? palette.border : borderColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 160),
|
||||
curve: Curves.easeOutCubic,
|
||||
child: widget.batchMode
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(right: AppDesignTokens.checkboxLabelGap),
|
||||
child: shad.Checkbox(
|
||||
state: widget.selectedInBatch
|
||||
? shad.CheckboxState.checked
|
||||
: shad.CheckboxState.unchecked,
|
||||
onChanged: (_) => widget.onToggleBatch(),
|
||||
borderColor: palette.border,
|
||||
backgroundColor: palette.cardBg,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
TaskCardIcon(task: task),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: palette.textPrimary,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (widget.listeningForUpdate) ...[
|
||||
const TaskUpdateListeningIndicator(),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
if (!widget.batchMode) ..._buildActionButtons(task, palette, isDark),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (task.status != TaskStatus.completed) ...[
|
||||
TaskProgressBar(
|
||||
value: task.progress,
|
||||
indeterminate: task.isIndeterminate,
|
||||
trackColor: palette.brandTrack,
|
||||
fillColor: fillColor,
|
||||
highlightStartColor: fillColor,
|
||||
highlightEndColor: fillColor,
|
||||
shimmer: task.status == TaskStatus.downloading,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
TaskCardFooter(task: task, isError: task.status == TaskStatus.failed),
|
||||
] else ...[
|
||||
TaskCardCompletedMeta(task: task),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildActionButtons(TaskRecord task, AppPalette palette, bool isDark) {
|
||||
final actions = switch (task.status) {
|
||||
TaskStatus.downloading => [(Icons.pause, widget.onPause), (Icons.close, widget.onDelete)],
|
||||
TaskStatus.paused => [(Icons.play_arrow, widget.onResume), (Icons.close, widget.onDelete)],
|
||||
TaskStatus.failed => [(Icons.refresh, widget.onResume), (Icons.delete_outline, widget.onDelete)],
|
||||
TaskStatus.completed => [(Icons.folder_open_outlined, widget.onReveal), (Icons.delete_outline, widget.onDelete)],
|
||||
};
|
||||
|
||||
return actions
|
||||
.map(
|
||||
(action) => TaskCardActionButton(
|
||||
icon: action.$1,
|
||||
color: palette.taskCardAction,
|
||||
onPressed: action.$2 ?? () {},
|
||||
hoverBackground: isDark ? palette.border : Colors.transparent,
|
||||
buttonSize: 20,
|
||||
iconSize: 13,
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
import 'package:flutter/material.dart' show Colors, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../domain/task_record.dart';
|
||||
import '../../../../../shared/theme/app_design_tokens.dart';
|
||||
import '../../../../../shared/theme/app_palette.dart';
|
||||
import '../../../../../shared/widgets/app_tooltip.dart';
|
||||
import '../../../../../l10n/l10n.dart';
|
||||
import '../../task_record_localizations.dart';
|
||||
|
||||
Color taskCardFillColor(AppPalette palette, TaskStatus status, bool isDark) {
|
||||
if (isDark) {
|
||||
switch (status) {
|
||||
case TaskStatus.failed:
|
||||
return palette.error;
|
||||
case TaskStatus.paused:
|
||||
return palette.textMuted;
|
||||
case TaskStatus.downloading:
|
||||
case TaskStatus.completed:
|
||||
return palette.brandProgress;
|
||||
}
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case TaskStatus.failed:
|
||||
return palette.error;
|
||||
case TaskStatus.paused:
|
||||
return palette.textMuted;
|
||||
case TaskStatus.downloading:
|
||||
case TaskStatus.completed:
|
||||
return palette.brandProgress;
|
||||
}
|
||||
}
|
||||
|
||||
class TaskUpdateListeningIndicator extends StatelessWidget {
|
||||
const TaskUpdateListeningIndicator({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return AppTooltip(
|
||||
message: context.l10n.waitingForReplacementUrl,
|
||||
child: Icon(Icons.hearing, size: 15, color: palette.brandProgress),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TaskCardIcon extends StatelessWidget {
|
||||
const TaskCardIcon({super.key, required this.task});
|
||||
|
||||
final TaskRecord task;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
|
||||
return SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: ColoredBox(
|
||||
color: palette.taskCardIconBg,
|
||||
child: Center(child: Icon(task.icon, size: 20, color: palette.textSecondary)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TaskCardFooter extends StatelessWidget {
|
||||
const TaskCardFooter({super.key, required this.task, required this.isError});
|
||||
|
||||
final TaskRecord task;
|
||||
final bool isError;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final metaColor = palette.taskMeta;
|
||||
final leftColor = isError ? palette.error : metaColor;
|
||||
final rightColor = isError ? palette.taskErrorMeta : metaColor;
|
||||
final statusText = switch (task.status) {
|
||||
TaskStatus.downloading => task.localizedRemaining(context.l10n) ?? context.l10n.downloading,
|
||||
TaskStatus.paused => task.localizedRemaining(context.l10n) ?? context.l10n.pause,
|
||||
TaskStatus.completed => context.l10n.completed,
|
||||
TaskStatus.failed => context.l10n.failed,
|
||||
};
|
||||
|
||||
return SizedBox(
|
||||
height: 10,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.total != null ? '${task.downloaded} / ${task.total}' : context.l10n.unknownSize,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: leftColor, fontSize: 10, height: 1),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
if (task.speed != null && !isError) ...[
|
||||
_TaskTransferSpeed(icon: Icons.south, value: task.speed!, color: metaColor),
|
||||
const SizedBox(width: 8),
|
||||
TickDivider(color: palette.progressTrack),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
if (task.uploading) ...[
|
||||
_TaskTransferSpeed(icon: Icons.north, value: task.uploadSpeed!, color: metaColor),
|
||||
const SizedBox(width: 8),
|
||||
TickDivider(color: palette.progressTrack),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Text(
|
||||
statusText,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: rightColor, fontSize: 10, height: 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TaskCardCompletedMeta extends StatelessWidget {
|
||||
const TaskCardCompletedMeta({super.key, required this.task});
|
||||
|
||||
final TaskRecord task;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final metaColor = palette.taskMeta;
|
||||
|
||||
return SizedBox(
|
||||
height: 10,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.total ?? task.downloaded,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: metaColor, fontSize: 10, height: 1),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
if (task.speed != null) ...[
|
||||
_TaskTransferSpeed(icon: Icons.south, value: task.speed!, color: metaColor),
|
||||
const SizedBox(width: 8),
|
||||
TickDivider(color: palette.progressTrack),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
if (task.uploading) ...[
|
||||
_TaskTransferSpeed(icon: Icons.north, value: task.uploadSpeed!, color: metaColor),
|
||||
const SizedBox(width: 8),
|
||||
TickDivider(color: palette.progressTrack),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Text(context.l10n.completed, style: TextStyle(color: palette.taskMetaSubtle, fontSize: 10, height: 1)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TaskTransferSpeed extends StatelessWidget {
|
||||
const _TaskTransferSpeed({required this.icon, required this.value, required this.color});
|
||||
|
||||
final IconData icon;
|
||||
final String value;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 10, color: color),
|
||||
const SizedBox(width: 2),
|
||||
Text(value, style: TextStyle(color: color, fontSize: 10, height: 1)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TickDivider extends StatelessWidget {
|
||||
const TickDivider({super.key, required this.color});
|
||||
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(999)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TaskCardActionButton extends StatelessWidget {
|
||||
const TaskCardActionButton({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.onPressed,
|
||||
required this.hoverBackground,
|
||||
this.buttonSize = 21,
|
||||
this.iconSize = 14,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final VoidCallback onPressed;
|
||||
final Color hoverBackground;
|
||||
final double buttonSize;
|
||||
final double iconSize;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 4),
|
||||
child: HoverActionButton(
|
||||
hoverBackground: hoverBackground,
|
||||
onPressed: onPressed,
|
||||
child: SizedBox(
|
||||
width: buttonSize,
|
||||
height: buttonSize,
|
||||
child: Center(
|
||||
child: Icon(icon, size: iconSize, color: color),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HoverActionButton extends StatefulWidget {
|
||||
const HoverActionButton({super.key, required this.child, required this.onPressed, required this.hoverBackground});
|
||||
|
||||
final Widget child;
|
||||
final VoidCallback onPressed;
|
||||
final Color hoverBackground;
|
||||
|
||||
@override
|
||||
State<HoverActionButton> createState() => _HoverActionButtonState();
|
||||
}
|
||||
|
||||
class _HoverActionButtonState extends State<HoverActionButton> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.onPressed,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 140),
|
||||
decoration: BoxDecoration(
|
||||
color: _hovered ? widget.hoverBackground : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user