feat: new ui (#1455)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 19:53:41 +08:00
1 parent 3be8db664c
commit 177c225f16
742 files changed
+59951 -5934

No files matched your search

@@ -0,0 +1,24 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import '../../l10n/l10n.dart';
import '../widgets/app_toast.dart';
class AppExitConfirmationController {
static const confirmationWindow = Duration(seconds: 2);
DateTime? _lastBackAt;
Future<void> handleBack(BuildContext context) async {
final now = DateTime.now();
final lastBackAt = _lastBackAt;
if (lastBackAt != null && now.difference(lastBackAt) <= confirmationWindow) {
_lastBackAt = null;
await SystemNavigator.pop();
return;
}
_lastBackAt = now;
showAppToast(context, context.l10n.pressBackAgainToExit);
}
}
@@ -0,0 +1,13 @@
import 'dart:io';
import 'package:path/path.dart' as path;
Future<void> verifyDownloadDirectoryWritable(String directoryPath) async {
final probe = File(path.join(directoryPath, '.gopeed-write-test-${DateTime.now().microsecondsSinceEpoch}.tmp'));
try {
await probe.create(recursive: true);
await probe.writeAsString('test', flush: true);
} finally {
if (await probe.exists()) await probe.delete();
}
}
@@ -0,0 +1,2 @@
Future<void> verifyDownloadDirectoryWritable(String directoryPath) =>
Future<void>.error(UnsupportedError('Directory write checks are unavailable on this platform'));
@@ -0,0 +1,12 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
TargetPlatform get downloadDirectoryHostPlatform {
if (Platform.isAndroid) return TargetPlatform.android;
if (Platform.isIOS) return TargetPlatform.iOS;
if (Platform.isWindows) return TargetPlatform.windows;
if (Platform.isLinux) return TargetPlatform.linux;
if (Platform.isMacOS) return TargetPlatform.macOS;
return defaultTargetPlatform;
}
@@ -0,0 +1,3 @@
import 'package:flutter/foundation.dart';
TargetPlatform get downloadDirectoryHostPlatform => defaultTargetPlatform;
@@ -0,0 +1,224 @@
import 'package:file_picker/file_picker.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:external_path/external_path.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' show Icons;
import 'package:flutter/widgets.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../../l10n/l10n.dart';
import '../theme/app_palette.dart';
import 'download_directory_file_stub.dart' if (dart.library.io) 'download_directory_file_io.dart';
import 'download_directory_host_platform_stub.dart' if (dart.library.io) 'download_directory_host_platform_io.dart';
/// Keeps directory selection compatible with the raw paths consumed by the Go
/// downloader. Android therefore exposes only paths whose writability can be
/// verified without relying on a persisted Storage Access Framework URI.
class DownloadDirectoryPicker {
DownloadDirectoryPicker._();
@visibleForTesting
static TargetPlatform? debugPlatformOverride;
@visibleForTesting
static bool? debugWebOverride;
@visibleForTesting
static Future<Map<String, String>?> Function()? debugAndroidLocationsLoader;
@visibleForTesting
static Future<String> Function(String path)? debugDownloadsPreparer;
static TargetPlatform get _platform {
final override = debugPlatformOverride;
if (override != null) return override;
return downloadDirectoryHostPlatform;
}
static bool get isWeb => debugWebOverride ?? kIsWeb;
static bool get isAndroid => !isWeb && _platform == TargetPlatform.android;
static bool get isIOS => !isWeb && _platform == TargetPlatform.iOS;
static bool get isMobile => isAndroid || isIOS;
static bool get canPick => !isWeb && _platform != TargetPlatform.iOS;
static bool canEditManually({bool allowAndroidEditing = false}) {
return isWeb || !isMobile || (isAndroid && allowAndroidEditing);
}
static Future<String?> pick(BuildContext context, {required String currentPath}) async {
if (isWeb) return null;
if (_platform == TargetPlatform.android) {
return _pickAndroid(context, currentPath: currentPath);
}
if (_platform == TargetPlatform.iOS) return null;
return FilePicker.platform.getDirectoryPath();
}
static Future<String?> _pickAndroid(BuildContext context, {required String currentPath}) async {
final locations = await _loadAndroidLocations();
if (!context.mounted || locations == null) return null;
final applicationPath = locations['application'];
final downloadsPath = locations['downloads'];
if (applicationPath == null || applicationPath.isEmpty || downloadsPath == null || downloadsPath.isEmpty) {
return null;
}
String? errorMessage;
var checkingDownloads = false;
final overlay = const shad.DialogOverlayHandler().show<String?>(
context: context,
alignment: Alignment.center,
barrierDismissable: false,
builder: (dialogContext) => StatefulBuilder(
builder: (dialogContext, setDialogState) {
Future<void> chooseDownloads() async {
if (checkingDownloads) return;
setDialogState(() {
checkingDownloads = true;
errorMessage = null;
});
try {
final verifiedPath = await _prepareDownloads(downloadsPath);
if (dialogContext.mounted && verifiedPath.isNotEmpty) {
shad.closeOverlay(dialogContext, verifiedPath);
}
} catch (_) {
if (dialogContext.mounted) {
setDialogState(() => errorMessage = dialogContext.l10n.downloadsDirectoryUnavailable);
}
} finally {
if (dialogContext.mounted) setDialogState(() => checkingDownloads = false);
}
}
return shad.AlertDialog(
key: const ValueKey('android-download-directory-dialog'),
title: Text(dialogContext.l10n.chooseDownloadDirectory),
content: SizedBox(
width: (MediaQuery.sizeOf(dialogContext).width - 64).clamp(260.0, 400.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_DirectoryOption(
key: const ValueKey('android-app-directory-option'),
icon: Icons.smartphone_outlined,
title: dialogContext.l10n.applicationStorage,
description: dialogContext.l10n.applicationStorageDescription,
selected: currentPath == applicationPath,
onPressed: checkingDownloads ? null : () => shad.closeOverlay(dialogContext, applicationPath),
),
const SizedBox(height: 8),
_DirectoryOption(
key: const ValueKey('android-downloads-directory-option'),
icon: Icons.download_outlined,
title: 'Download/Gopeed',
description: dialogContext.l10n.publicDownloadsDescription,
selected: currentPath == downloadsPath,
loading: checkingDownloads,
onPressed: checkingDownloads ? null : chooseDownloads,
),
if (errorMessage != null) ...[
const SizedBox(height: 8),
Text(
errorMessage!,
style: TextStyle(color: AppPalette.of(dialogContext).error, fontSize: 12, height: 1.3),
),
],
],
),
),
actions: [
shad.SecondaryButton(
onPressed: checkingDownloads ? null : () => shad.closeOverlay(dialogContext),
child: Text(dialogContext.l10n.cancel),
),
],
);
},
),
);
return overlay.future;
}
static Future<Map<String, String>?> _loadAndroidLocations() async {
final debugLoader = debugAndroidLocationsLoader;
if (debugLoader != null) return debugLoader();
final applicationDirectory = await getExternalStorageDirectory() ?? await getApplicationDocumentsDirectory();
final downloadsDirectory = await ExternalPath.getExternalStoragePublicDirectory(ExternalPath.DIRECTORY_DOWNLOAD);
if (downloadsDirectory.isEmpty) return null;
return {'application': applicationDirectory.path, 'downloads': path.join(downloadsDirectory, 'Gopeed')};
}
static Future<String> _prepareDownloads(String downloadsPath) async {
final debugPreparer = debugDownloadsPreparer;
if (debugPreparer != null) return debugPreparer(downloadsPath);
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (androidInfo.version.sdkInt < 30) {
var permission = await Permission.storage.status;
if (!permission.isGranted) permission = await Permission.storage.request();
if (!permission.isGranted) throw StateError('Storage permission was denied');
}
await verifyDownloadDirectoryWritable(downloadsPath);
return downloadsPath;
}
}
class _DirectoryOption extends StatelessWidget {
const _DirectoryOption({
super.key,
required this.icon,
required this.title,
required this.description,
required this.selected,
required this.onPressed,
this.loading = false,
});
final IconData icon;
final String title;
final String description;
final bool selected;
final VoidCallback? onPressed;
final bool loading;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return shad.SecondaryButton(
onPressed: onPressed,
child: SizedBox(
width: double.infinity,
child: Row(
children: [
Icon(icon, size: 20, color: palette.textSecondary),
const SizedBox(width: 10),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: TextStyle(color: palette.textPrimary, fontSize: 13)),
const SizedBox(height: 2),
Text(description, style: TextStyle(color: palette.textSecondary, fontSize: 11, height: 1.25)),
],
),
),
const SizedBox(width: 8),
if (loading)
const SizedBox.square(dimension: 15, child: shad.CircularProgressIndicator())
else if (selected)
Icon(Icons.check_circle_outline, size: 18, color: palette.success),
],
),
),
);
}
}
@@ -0,0 +1,62 @@
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import 'app_design_tokens.dart';
import 'app_palette.dart';
class AppComponentThemes extends StatelessWidget {
const AppComponentThemes({super.key, required this.child});
final Widget child;
@override
Widget build(BuildContext context) {
final theme = shad.Theme.of(context);
final palette = AppPalette.of(context);
return shad.ComponentTheme<shad.FocusOutlineTheme>(
data: shad.FocusOutlineTheme(
align: 1,
border: Border.all(color: theme.colorScheme.ring.withValues(alpha: 0.65), width: 1),
),
child: shad.ComponentTheme<shad.SecondaryButtonTheme>(
data: shad.SecondaryButtonTheme(
decoration: (context, states, value) {
final decoration = switch (value) {
final BoxDecoration decoration => decoration,
_ => BoxDecoration(borderRadius: BorderRadius.circular(theme.radiusMd)),
};
if (states.contains(WidgetState.disabled)) {
return decoration.copyWith(color: palette.surfaceSoft);
}
if (theme.brightness == Brightness.light) {
final background = Color.alphaBlend(palette.textPrimary.withValues(alpha: 0.08), palette.surfaceSoft);
final hoverBackground = Color.alphaBlend(
palette.textPrimary.withValues(alpha: 0.13),
palette.surfaceSoft,
);
return decoration.copyWith(color: states.contains(WidgetState.hovered) ? hoverBackground : background);
}
return value;
},
textStyle: (context, states, value) => states.contains(WidgetState.disabled)
? value.copyWith(color: palette.textMuted.withValues(alpha: 0.62))
: value,
iconTheme: (context, states, value) => states.contains(WidgetState.disabled)
? value.copyWith(color: palette.textMuted.withValues(alpha: 0.62))
: value,
),
child: shad.ComponentTheme<shad.CheckboxTheme>(
data: shad.CheckboxTheme(
size: AppDesignTokens.checkboxSize,
gap: AppDesignTokens.checkboxLabelGap,
borderColor: theme.brightness == Brightness.dark ? palette.textMuted : palette.border,
),
child: shad.ComponentTheme<shad.ToastTheme>(
data: const shad.ToastTheme(toastConstraints: BoxConstraints(maxWidth: 420)),
child: child,
),
),
),
);
}
}
@@ -0,0 +1,40 @@
import 'package:flutter/widgets.dart';
class AppDesignTokens {
const AppDesignTokens._();
static const double windowHeaderHeight = 30;
static const double windowRadius = 12;
static const double railWidth = 68;
static const double filterSidebarWidth = 192;
static const double contentHeaderHeight = 48;
static const double taskRowHeight = 72;
static const double controlRadius = 4;
static const double checkboxSize = 18;
static const double checkboxLabelGap = 10;
static const double taskDetailsDrawerMinWidth = 440;
static const double taskDetailsDrawerMaxWidth = 720;
static const double taskDetailsDrawerViewportRatio = 0.42;
static const double taskDetailsDesktopPadding = 24;
static const double taskDetailsMobilePadding = 16;
static const double settingsContentMaxWidth = 920;
static const double settingsFormControlWidth = 420;
static const double settingsNumberControlWidth = 168;
static const double settingsItemMinLabelWidth = 160;
static const EdgeInsets pagePadding = EdgeInsets.symmetric(horizontal: 32);
static const EdgeInsets sidebarPadding = EdgeInsets.symmetric(horizontal: 16);
static const double space4 = 4;
static const double space8 = 8;
static const double space12 = 12;
static const double space16 = 16;
static const double space24 = 24;
static const double space32 = 32;
static double taskDetailsDrawerWidth(double viewportWidth) {
return (viewportWidth * taskDetailsDrawerViewportRatio)
.clamp(taskDetailsDrawerMinWidth, taskDetailsDrawerMaxWidth)
.toDouble();
}
}
@@ -0,0 +1,363 @@
import 'package:flutter/material.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import 'app_theme_color.dart';
class AppPalette extends ThemeExtension<AppPalette> {
const AppPalette({
required this.bg,
required this.railBg,
required this.sideBg,
required this.cardBg,
required this.cardHoverBg,
required this.surfaceSoft,
required this.inputBg,
required this.footerBg,
required this.border,
required this.textPrimary,
required this.textSecondary,
required this.textMuted,
required this.primaryActionBg,
required this.primaryActionForeground,
required this.primaryActionHoverBg,
required this.brand,
required this.brandForeground,
required this.brandSoft,
required this.brandTrack,
required this.brandProgress,
required this.accent,
required this.accentOn,
required this.error,
required this.success,
required this.toggleBg,
required this.toggleIcon,
required this.itemActiveBg,
required this.filterActiveBg,
required this.progressTrack,
required this.taskCardSelectedBorder,
required this.taskCardHoverBg,
required this.taskCardAction,
required this.taskCardProgressFill,
required this.taskCardIconBg,
required this.taskCardFailedIconBg,
required this.taskMeta,
required this.taskMetaSubtle,
required this.taskErrorMeta,
required this.searchHint,
required this.headerDivider,
required this.captionButtonHover,
required this.captionButtonCloseHover,
});
static const Color lightAccent = Color(0xFF79C476);
static const light = AppPalette(
bg: Color(0xFFF6F8F7),
railBg: Color(0xFFE8EEEA),
sideBg: Color(0xFFF0F4F1),
cardBg: Color(0xFFFFFFFF),
cardHoverBg: Color(0xFFF5F7F5),
surfaceSoft: Color(0xFFEDF0EE),
inputBg: Color(0xFFE7E8E9),
footerBg: Color(0xFFF3F4F5),
border: Color(0x66C0C9BA),
textPrimary: Color(0xFF191C1D),
textSecondary: Color(0xFF5F6368),
textMuted: Color(0xFF707A6D),
primaryActionBg: Color(0xFF191C1D),
primaryActionForeground: Color(0xFFFFFFFF),
primaryActionHoverBg: Color(0xFF303435),
brand: lightAccent,
brandForeground: Color(0xFFFFFFFF),
brandSoft: Color(0x1479C476),
brandTrack: Color(0x2679C476),
brandProgress: Color(0xFF79C476),
accent: Color(0xFFE7E8E9),
accentOn: Color(0xFFF4F7F6),
error: Color(0xFFBA1A1A),
success: Color(0xFF2E7D32),
toggleBg: Color(0xFFFFFFFF),
toggleIcon: Color(0xFF5F6368),
itemActiveBg: Color(0x0F191C1D),
filterActiveBg: Color(0x3379C476),
progressTrack: Color(0x33C0C9BA),
taskCardSelectedBorder: Color(0x24191C1D),
taskCardHoverBg: Color(0xFFEAF0EC),
taskCardAction: Color(0xFF5F6368),
taskCardProgressFill: Color(0xFF79C476),
taskCardIconBg: Color(0xFFF5F7F5),
taskCardFailedIconBg: Color(0x14BA1A1A),
taskMeta: Color(0xFF5F6368),
taskMetaSubtle: Color(0xFF707A6D),
taskErrorMeta: Color(0xCCBA1A1A),
searchHint: Color(0xFF707A6D),
headerDivider: Color(0xA3C0C9BA),
captionButtonHover: Color(0x0F191C1D),
captionButtonCloseHover: Color(0xFFE81123),
);
static final dark = AppPalette(
bg: const Color(0xFF09090B),
railBg: Colors.black,
sideBg: const Color(0xFF111111),
cardBg: const Color(0xFF0F0F11),
cardHoverBg: const Color(0xFF121215),
surfaceSoft: const Color(0xFF1F1F24),
inputBg: const Color(0xFF111111),
footerBg: Colors.black.withValues(alpha: 0.2),
border: const Color(0xFF1B1B1D),
textPrimary: const Color(0xFFFFFFFF),
textSecondary: const Color(0xFFA1A1AA),
textMuted: const Color(0xFF71717A),
primaryActionBg: const Color(0xFFFAFAFA),
primaryActionForeground: const Color(0xFF18181B),
primaryActionHoverBg: const Color(0xFFE4E4E7),
brand: const Color(0xFFA7F5A2),
brandForeground: const Color(0xFF07310B),
brandSoft: const Color(0x1AA7F5A2),
brandTrack: const Color(0x2CA7F5A2),
brandProgress: const Color(0xFFA7F5A2),
accent: const Color(0xFF111111),
accentOn: const Color(0xFF09090B),
error: const Color(0xFFFFB4AB),
success: const Color(0xFF81C784),
toggleBg: Colors.white.withValues(alpha: 0.08),
toggleIcon: const Color(0xFFA1A1AA),
itemActiveBg: Colors.white.withValues(alpha: 0.08),
filterActiveBg: const Color(0x3DA7F5A2),
progressTrack: const Color(0xFF272729),
taskCardSelectedBorder: const Color(0xFF3F3F41),
taskCardHoverBg: const Color(0xFF171719),
taskCardAction: const Color(0xFFC6C6C6),
taskCardProgressFill: const Color(0xFFA7F5A2),
taskCardIconBg: const Color(0xFF1B1B1E),
taskCardFailedIconBg: const Color(0xFF272020),
taskMeta: const Color(0xFF8F8F90),
taskMetaSubtle: const Color(0xFF6B6B6C),
taskErrorMeta: const Color(0xFFCF938C),
searchHint: const Color(0xFF52525B),
headerDivider: const Color(0x1AFFFFFF),
captionButtonHover: const Color(0x0DFFFFFF),
captionButtonCloseHover: const Color(0xFFE81123),
);
static AppPalette lightFor(AppThemeColor themeColor) {
if (themeColor == AppThemeColor.green) return light;
return _withThemeColor(light, color: themeColor.light, foreground: themeColor.lightForeground, dark: false);
}
static AppPalette darkFor(AppThemeColor themeColor) {
if (themeColor == AppThemeColor.green) return dark;
return _withThemeColor(dark, color: themeColor.dark, foreground: themeColor.darkForeground, dark: true);
}
static AppPalette _withThemeColor(
AppPalette palette, {
required Color color,
required Color foreground,
required bool dark,
}) {
return palette.copyWith(
brand: color,
brandForeground: foreground,
brandSoft: color.withValues(alpha: dark ? 0.10 : 0.08),
brandTrack: color.withValues(alpha: dark ? 0.17 : 0.15),
brandProgress: color,
filterActiveBg: color.withValues(alpha: dark ? 0.24 : 0.20),
taskCardProgressFill: color,
);
}
final Color bg;
final Color railBg;
final Color sideBg;
final Color cardBg;
final Color cardHoverBg;
final Color surfaceSoft;
final Color inputBg;
final Color footerBg;
final Color border;
final Color textPrimary;
final Color textSecondary;
final Color textMuted;
final Color primaryActionBg;
final Color primaryActionForeground;
final Color primaryActionHoverBg;
final Color brand;
final Color brandForeground;
final Color brandSoft;
final Color brandTrack;
final Color brandProgress;
final Color accent;
final Color accentOn;
final Color error;
final Color success;
final Color toggleBg;
final Color toggleIcon;
final Color itemActiveBg;
final Color filterActiveBg;
final Color progressTrack;
final Color taskCardSelectedBorder;
final Color taskCardHoverBg;
final Color taskCardAction;
final Color taskCardProgressFill;
final Color taskCardIconBg;
final Color taskCardFailedIconBg;
final Color taskMeta;
final Color taskMetaSubtle;
final Color taskErrorMeta;
final Color searchHint;
final Color headerDivider;
final Color captionButtonHover;
final Color captionButtonCloseHover;
static AppPalette of(BuildContext context) {
final extension = Theme.of(context).extension<AppPalette>();
if (extension != null) {
return extension;
}
return shad.Theme.of(context).brightness == Brightness.light ? light : dark;
}
@override
AppPalette copyWith({
Color? bg,
Color? railBg,
Color? sideBg,
Color? cardBg,
Color? cardHoverBg,
Color? surfaceSoft,
Color? inputBg,
Color? footerBg,
Color? border,
Color? textPrimary,
Color? textSecondary,
Color? textMuted,
Color? primaryActionBg,
Color? primaryActionForeground,
Color? primaryActionHoverBg,
Color? brand,
Color? brandForeground,
Color? brandSoft,
Color? brandTrack,
Color? brandProgress,
Color? accent,
Color? accentOn,
Color? error,
Color? success,
Color? toggleBg,
Color? toggleIcon,
Color? itemActiveBg,
Color? filterActiveBg,
Color? progressTrack,
Color? taskCardSelectedBorder,
Color? taskCardHoverBg,
Color? taskCardAction,
Color? taskCardProgressFill,
Color? taskCardIconBg,
Color? taskCardFailedIconBg,
Color? taskMeta,
Color? taskMetaSubtle,
Color? taskErrorMeta,
Color? searchHint,
Color? headerDivider,
Color? captionButtonHover,
Color? captionButtonCloseHover,
}) {
return AppPalette(
bg: bg ?? this.bg,
railBg: railBg ?? this.railBg,
sideBg: sideBg ?? this.sideBg,
cardBg: cardBg ?? this.cardBg,
cardHoverBg: cardHoverBg ?? this.cardHoverBg,
surfaceSoft: surfaceSoft ?? this.surfaceSoft,
inputBg: inputBg ?? this.inputBg,
footerBg: footerBg ?? this.footerBg,
border: border ?? this.border,
textPrimary: textPrimary ?? this.textPrimary,
textSecondary: textSecondary ?? this.textSecondary,
textMuted: textMuted ?? this.textMuted,
primaryActionBg: primaryActionBg ?? this.primaryActionBg,
primaryActionForeground: primaryActionForeground ?? this.primaryActionForeground,
primaryActionHoverBg: primaryActionHoverBg ?? this.primaryActionHoverBg,
brand: brand ?? this.brand,
brandForeground: brandForeground ?? this.brandForeground,
brandSoft: brandSoft ?? this.brandSoft,
brandTrack: brandTrack ?? this.brandTrack,
brandProgress: brandProgress ?? this.brandProgress,
accent: accent ?? this.accent,
accentOn: accentOn ?? this.accentOn,
error: error ?? this.error,
success: success ?? this.success,
toggleBg: toggleBg ?? this.toggleBg,
toggleIcon: toggleIcon ?? this.toggleIcon,
itemActiveBg: itemActiveBg ?? this.itemActiveBg,
filterActiveBg: filterActiveBg ?? this.filterActiveBg,
progressTrack: progressTrack ?? this.progressTrack,
taskCardSelectedBorder: taskCardSelectedBorder ?? this.taskCardSelectedBorder,
taskCardHoverBg: taskCardHoverBg ?? this.taskCardHoverBg,
taskCardAction: taskCardAction ?? this.taskCardAction,
taskCardProgressFill: taskCardProgressFill ?? this.taskCardProgressFill,
taskCardIconBg: taskCardIconBg ?? this.taskCardIconBg,
taskCardFailedIconBg: taskCardFailedIconBg ?? this.taskCardFailedIconBg,
taskMeta: taskMeta ?? this.taskMeta,
taskMetaSubtle: taskMetaSubtle ?? this.taskMetaSubtle,
taskErrorMeta: taskErrorMeta ?? this.taskErrorMeta,
searchHint: searchHint ?? this.searchHint,
headerDivider: headerDivider ?? this.headerDivider,
captionButtonHover: captionButtonHover ?? this.captionButtonHover,
captionButtonCloseHover: captionButtonCloseHover ?? this.captionButtonCloseHover,
);
}
@override
AppPalette lerp(ThemeExtension<AppPalette>? other, double t) {
if (other is! AppPalette) {
return this;
}
return AppPalette(
bg: Color.lerp(bg, other.bg, t)!,
railBg: Color.lerp(railBg, other.railBg, t)!,
sideBg: Color.lerp(sideBg, other.sideBg, t)!,
cardBg: Color.lerp(cardBg, other.cardBg, t)!,
cardHoverBg: Color.lerp(cardHoverBg, other.cardHoverBg, t)!,
surfaceSoft: Color.lerp(surfaceSoft, other.surfaceSoft, t)!,
inputBg: Color.lerp(inputBg, other.inputBg, t)!,
footerBg: Color.lerp(footerBg, other.footerBg, t)!,
border: Color.lerp(border, other.border, t)!,
textPrimary: Color.lerp(textPrimary, other.textPrimary, t)!,
textSecondary: Color.lerp(textSecondary, other.textSecondary, t)!,
textMuted: Color.lerp(textMuted, other.textMuted, t)!,
primaryActionBg: Color.lerp(primaryActionBg, other.primaryActionBg, t)!,
primaryActionForeground: Color.lerp(primaryActionForeground, other.primaryActionForeground, t)!,
primaryActionHoverBg: Color.lerp(primaryActionHoverBg, other.primaryActionHoverBg, t)!,
brand: Color.lerp(brand, other.brand, t)!,
brandForeground: Color.lerp(brandForeground, other.brandForeground, t)!,
brandSoft: Color.lerp(brandSoft, other.brandSoft, t)!,
brandTrack: Color.lerp(brandTrack, other.brandTrack, t)!,
brandProgress: Color.lerp(brandProgress, other.brandProgress, t)!,
accent: Color.lerp(accent, other.accent, t)!,
accentOn: Color.lerp(accentOn, other.accentOn, t)!,
error: Color.lerp(error, other.error, t)!,
success: Color.lerp(success, other.success, t)!,
toggleBg: Color.lerp(toggleBg, other.toggleBg, t)!,
toggleIcon: Color.lerp(toggleIcon, other.toggleIcon, t)!,
itemActiveBg: Color.lerp(itemActiveBg, other.itemActiveBg, t)!,
filterActiveBg: Color.lerp(filterActiveBg, other.filterActiveBg, t)!,
progressTrack: Color.lerp(progressTrack, other.progressTrack, t)!,
taskCardSelectedBorder: Color.lerp(taskCardSelectedBorder, other.taskCardSelectedBorder, t)!,
taskCardHoverBg: Color.lerp(taskCardHoverBg, other.taskCardHoverBg, t)!,
taskCardAction: Color.lerp(taskCardAction, other.taskCardAction, t)!,
taskCardProgressFill: Color.lerp(taskCardProgressFill, other.taskCardProgressFill, t)!,
taskCardIconBg: Color.lerp(taskCardIconBg, other.taskCardIconBg, t)!,
taskCardFailedIconBg: Color.lerp(taskCardFailedIconBg, other.taskCardFailedIconBg, t)!,
taskMeta: Color.lerp(taskMeta, other.taskMeta, t)!,
taskMetaSubtle: Color.lerp(taskMetaSubtle, other.taskMetaSubtle, t)!,
taskErrorMeta: Color.lerp(taskErrorMeta, other.taskErrorMeta, t)!,
searchHint: Color.lerp(searchHint, other.searchHint, t)!,
headerDivider: Color.lerp(headerDivider, other.headerDivider, t)!,
captionButtonHover: Color.lerp(captionButtonHover, other.captionButtonHover, t)!,
captionButtonCloseHover: Color.lerp(captionButtonCloseHover, other.captionButtonCloseHover, t)!,
);
}
}
+117
View File
@@ -0,0 +1,117 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' as material;
import 'package:flutter/painting.dart' show TextStyle;
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import 'app_palette.dart';
import 'app_theme_color.dart';
class AppTheme {
const AppTheme._();
// Flutter's automatic CJK fallback can select faces with mismatched weights
// on Windows. Keep Geist for supported glyphs, but make the native Windows
// UI font the deterministic fallback for Chinese text.
static const _windowsFontFamilyFallback = <String>['Microsoft YaHei UI'];
static bool get _usesWindowsFontFallback => !kIsWeb && defaultTargetPlatform == TargetPlatform.windows;
static shad.Typography _typography() {
if (defaultTargetPlatform == TargetPlatform.android) return _androidTypography;
const typography = shad.Typography.geist();
if (!_usesWindowsFontFallback) return typography;
return typography.copyWith(
// Do not pass `package` here: Flutter prefixes every fallback family
// with the package name when it is set, including system font names.
sans: () => const TextStyle(
fontFamily: 'packages/shadcn_flutter/GeistSans',
fontFamilyFallback: _windowsFontFamilyFallback,
),
);
}
static shad.ThemeData light([AppThemeColor themeColor = AppThemeColor.green]) {
return _buildTheme(palette: AppPalette.lightFor(themeColor), brightness: Brightness.light);
}
static shad.ThemeData dark([AppThemeColor themeColor = AppThemeColor.green]) {
return _buildTheme(palette: AppPalette.darkFor(themeColor), brightness: Brightness.dark);
}
static shad.ThemeData _buildTheme({required AppPalette palette, required Brightness brightness}) {
return shad.ThemeData(
colorScheme: shad.ColorScheme.fromColors(
brightness: brightness,
colors: {
'background': palette.bg,
'foreground': palette.textPrimary,
'card': palette.cardBg,
'cardForeground': palette.textPrimary,
'popover': palette.sideBg,
'popoverForeground': palette.textPrimary,
'primary': palette.brand,
'primaryForeground': palette.brandForeground,
'secondary': palette.surfaceSoft,
'secondaryForeground': palette.textPrimary,
'muted': palette.surfaceSoft,
'mutedForeground': palette.textSecondary,
'accent': palette.inputBg,
'accentForeground': palette.textPrimary,
'destructive': palette.error,
'destructiveForeground': palette.bg,
'border': palette.border,
'input': palette.border,
'ring': palette.brand,
'chart1': palette.brand,
'chart2': palette.textSecondary,
'chart3': palette.textMuted,
'chart4': palette.surfaceSoft,
'chart5': palette.cardHoverBg,
},
),
typography: _typography(),
radius: 0.5,
scaling: 1,
surfaceBlur: 0,
surfaceOpacity: 1,
platform: defaultTargetPlatform,
);
}
static const shad.Typography _androidTypography = shad.Typography.geist(
sans: material.TextStyle(),
mono: material.TextStyle(fontFamily: 'monospace'),
inlineCode: material.TextStyle(fontFamily: 'monospace', fontSize: 14, fontWeight: material.FontWeight.w600),
);
static material.ThemeData materialLight([AppThemeColor themeColor = AppThemeColor.green]) {
return _buildMaterialTheme(palette: AppPalette.lightFor(themeColor), brightness: Brightness.light);
}
static material.ThemeData materialDark([AppThemeColor themeColor = AppThemeColor.green]) {
return _buildMaterialTheme(palette: AppPalette.darkFor(themeColor), brightness: Brightness.dark);
}
static material.ThemeData _buildMaterialTheme({required AppPalette palette, required Brightness brightness}) {
final theme = material.ThemeData.from(
colorScheme: material.ColorScheme.fromSeed(
seedColor: palette.brand,
brightness: brightness,
surface: palette.bg,
primary: palette.brand,
),
useMaterial3: true,
);
return theme.copyWith(
extensions: <material.ThemeExtension<dynamic>>[palette],
textTheme: _usesWindowsFontFallback
? theme.textTheme.apply(fontFamilyFallback: _windowsFontFamilyFallback)
: theme.textTheme,
primaryTextTheme: _usesWindowsFontFallback
? theme.primaryTextTheme.apply(fontFamilyFallback: _windowsFontFamilyFallback)
: theme.primaryTextTheme,
);
}
}
@@ -0,0 +1,92 @@
import 'package:flutter/widgets.dart';
enum AppThemeColor {
green(
key: 'green',
light: Color(0xFF79C476),
dark: Color(0xFFA7F5A2),
lightForeground: Color(0xFFFFFFFF),
darkForeground: Color(0xFF07310B),
),
red(
key: 'red',
light: Color(0xFFE5484D),
dark: Color(0xFFFF8A8E),
lightForeground: Color(0xFFFFFFFF),
darkForeground: Color(0xFF3B0507),
),
rose(
key: 'rose',
light: Color(0xFFE93D82),
dark: Color(0xFFFF8AB7),
lightForeground: Color(0xFFFFFFFF),
darkForeground: Color(0xFF3B071B),
),
orange(
key: 'orange',
light: Color(0xFFF76B15),
dark: Color(0xFFFFA45B),
lightForeground: Color(0xFFFFFFFF),
darkForeground: Color(0xFF3A1600),
),
cyan(
key: 'cyan',
light: Color(0xFF0CA678),
dark: Color(0xFF5EE0B5),
lightForeground: Color(0xFFFFFFFF),
darkForeground: Color(0xFF003829),
),
blue(
key: 'blue',
light: Color(0xFF2563EB),
dark: Color(0xFF73A7FF),
lightForeground: Color(0xFFFFFFFF),
darkForeground: Color(0xFF061B3F),
),
amber(
key: 'amber',
light: Color(0xFFD99A00),
dark: Color(0xFFFFD166),
lightForeground: Color(0xFF211800),
darkForeground: Color(0xFF302300),
),
purple(
key: 'purple',
light: Color(0xFF8B5CF6),
dark: Color(0xFFB794F6),
lightForeground: Color(0xFFFFFFFF),
darkForeground: Color(0xFF261052),
);
const AppThemeColor({
required this.key,
required this.light,
required this.dark,
required this.lightForeground,
required this.darkForeground,
});
final String key;
final Color light;
final Color dark;
final Color lightForeground;
final Color darkForeground;
static AppThemeColor fromKey(String? key) {
return values.where((color) => color.key == key).firstOrNull ?? AppThemeColor.green;
}
}
class AppThemePreviewColors {
const AppThemePreviewColors._();
static const lightBackground = Color(0xFFF7F8F8);
static const lightSide = Color(0xFFE5E8E7);
static const lightLine = Color(0xFFB8BEBC);
static const darkBackground = Color(0xFF111318);
static const darkSide = Color(0xFF20242C);
static const darkLine = Color(0xFF676D78);
static const systemSide = Color(0x55878E8C);
static const systemLine = Color(0xFF7B8280);
static const transparent = Color(0x00000000);
}
@@ -0,0 +1,19 @@
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
class ActionIconButton extends StatelessWidget {
const ActionIconButton({super.key, required this.icon, required this.color, this.onTap});
final IconData icon;
final Color color;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return shad.IconButton.ghost(
onPressed: onTap,
density: shad.ButtonDensity.compact,
icon: Icon(icon, color: color, size: 18),
);
}
}
@@ -0,0 +1,100 @@
import 'package:flutter/widgets.dart';
import '../../core/utils/breakpoints.dart';
import '../theme/app_design_tokens.dart';
import '../theme/app_palette.dart';
class AppChoiceOption<T extends Object> {
const AppChoiceOption({required this.value, required this.label, required this.icon, this.key});
final T value;
final String label;
final IconData icon;
final String? key;
}
class AppChoiceSegmentedControl<T extends Object> extends StatelessWidget {
const AppChoiceSegmentedControl({
super.key,
required this.value,
required this.options,
required this.onChanged,
this.buttonKeyPrefix = 'choice',
this.alignment,
});
final T value;
final List<AppChoiceOption<T>> options;
final ValueChanged<T> onChanged;
final String buttonKeyPrefix;
final WrapAlignment? alignment;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final desktop = MediaQuery.sizeOf(context).width >= Breakpoints.mobile;
return Wrap(
spacing: 8,
runSpacing: 8,
alignment: alignment ?? (desktop ? WrapAlignment.end : WrapAlignment.start),
children: [
for (final option in options)
_ChoiceButton<T>(
key: ValueKey('$buttonKeyPrefix-${option.key ?? option.value}'),
option: option,
selected: option.value == value,
palette: palette,
onPressed: () => onChanged(option.value),
),
],
);
}
}
class _ChoiceButton<T extends Object> extends StatelessWidget {
const _ChoiceButton({
super.key,
required this.option,
required this.selected,
required this.palette,
required this.onPressed,
});
final AppChoiceOption<T> option;
final bool selected;
final AppPalette palette;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onPressed,
child: AnimatedContainer(
duration: const Duration(milliseconds: 140),
height: 34,
padding: const EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
color: selected ? palette.itemActiveBg : palette.cardBg,
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
border: Border.all(color: selected ? palette.textPrimary : palette.border),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(option.icon, size: 15, color: selected ? palette.textPrimary : palette.textSecondary),
const SizedBox(width: 7),
Text(
option.label,
style: TextStyle(
color: selected ? palette.textPrimary : palette.textSecondary,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
],
),
),
);
}
}
@@ -0,0 +1,200 @@
import 'package:flutter/material.dart' show Icons;
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../theme/app_design_tokens.dart';
import '../theme/app_palette.dart';
import '../../l10n/l10n.dart';
class AppHttpHeadersController extends ChangeNotifier {
AppHttpHeadersController({Map<String, String>? headers, Iterable<String> defaultNames = const []}) {
if (headers != null && headers.isNotEmpty) {
_rows.addAll(headers.entries.map((entry) => _HttpHeaderRowControllers(name: entry.key, value: entry.value)));
} else {
_rows.addAll(defaultNames.map((name) => _HttpHeaderRowControllers(name: name)));
}
_ensureRow();
}
final List<_HttpHeaderRowControllers> _rows = [];
void replace(Map<String, String> headers) {
for (final row in _rows) {
row.dispose();
}
_rows
..clear()
..addAll(headers.entries.map((entry) => _HttpHeaderRowControllers(name: entry.key, value: entry.value)));
_ensureRow();
notifyListeners();
}
Map<String, String> toMap({bool requireValue = false}) {
final headers = <String, String>{};
for (final row in _rows) {
final name = row.name.text.trim();
final value = row.value.text.trim();
if (name.isNotEmpty && (!requireValue || value.isNotEmpty)) {
headers[name] = value;
}
}
return headers;
}
void add() {
_rows.add(_HttpHeaderRowControllers());
notifyListeners();
}
void removeAt(int index) {
if (_rows.length == 1) return;
_rows.removeAt(index).dispose();
notifyListeners();
}
void _ensureRow() {
if (_rows.isEmpty) {
_rows.add(_HttpHeaderRowControllers());
}
}
@override
void dispose() {
for (final row in _rows) {
row.dispose();
}
super.dispose();
}
}
class AppHttpHeadersEditor extends StatelessWidget {
const AppHttpHeadersEditor({super.key, required this.controller, required this.label, required this.keyPrefix});
final AppHttpHeadersController controller;
final String label;
final String keyPrefix;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return Row(
key: ValueKey('$keyPrefix-editor'),
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 104,
child: Padding(
padding: const EdgeInsets.only(top: 10),
child: Text(
label,
style: TextStyle(color: palette.textPrimary, fontSize: 13, fontWeight: FontWeight.w500),
),
),
),
const SizedBox(width: 12),
Expanded(
child: AnimatedBuilder(
animation: controller,
builder: (context, _) => Column(
children: [
for (var index = 0; index < controller._rows.length; index++) ...[
Row(
children: [
Expanded(
flex: 382,
child: _HeaderTextField(
key: ValueKey('$keyPrefix-name-$index'),
controller: controller._rows[index].name,
hintText: context.l10n.httpHeaderName,
),
),
const SizedBox(width: 8),
Expanded(
flex: 618,
child: _HeaderTextField(
key: ValueKey('$keyPrefix-value-$index'),
controller: controller._rows[index].value,
hintText: context.l10n.httpHeaderValue,
),
),
const SizedBox(width: 4),
_HeaderAction(
key: ValueKey('$keyPrefix-remove-$index'),
icon: Icons.remove,
onPressed: controller._rows.length == 1 ? null : () => controller.removeAt(index),
),
const SizedBox(width: 4),
Visibility(
visible: index == controller._rows.length - 1,
maintainAnimation: true,
maintainSize: true,
maintainState: true,
child: _HeaderAction(
key: index == controller._rows.length - 1 ? ValueKey('$keyPrefix-add') : null,
icon: Icons.add,
onPressed: controller.add,
),
),
],
),
if (index != controller._rows.length - 1) const SizedBox(height: 8),
],
],
),
),
),
],
);
}
}
class _HttpHeaderRowControllers {
_HttpHeaderRowControllers({String name = '', String value = ''})
: name = TextEditingController(text: name),
value = TextEditingController(text: value);
final TextEditingController name;
final TextEditingController value;
void dispose() {
name.dispose();
value.dispose();
}
}
class _HeaderTextField extends StatelessWidget {
const _HeaderTextField({super.key, required this.controller, required this.hintText});
final TextEditingController controller;
final String hintText;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return shad.TextField(
controller: controller,
hintText: hintText,
filled: true,
border: Border.all(color: palette.border),
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
);
}
}
class _HeaderAction extends StatelessWidget {
const _HeaderAction({super.key, required this.icon, this.onPressed});
final IconData icon;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return shad.GhostButton(
density: shad.ButtonDensity.icon,
onPressed: onPressed,
child: Icon(icon, size: 14, color: palette.textSecondary),
);
}
}
@@ -0,0 +1,108 @@
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../theme/app_design_tokens.dart';
import '../theme/app_palette.dart';
import 'app_primary_button.dart';
enum AppLoadingButtonVariant { secondary, primary, brand }
class AppLoadingButton extends StatelessWidget {
const AppLoadingButton({
super.key,
required this.onPressed,
required this.loading,
required this.child,
this.icon,
this.alignment,
this.variant = AppLoadingButtonVariant.secondary,
});
final VoidCallback? onPressed;
final bool loading;
final Widget child;
final Widget? icon;
final AlignmentGeometry? alignment;
final AppLoadingButtonVariant variant;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final replaceChild = loading && icon == null;
final leading = loading && icon != null ? _LoadingIcon(variant: variant) : icon;
final effectiveChild = replaceChild ? _LoadingIcon(variant: variant) : child;
final effectiveOnPressed = loading ? null : onPressed;
return switch (variant) {
AppLoadingButtonVariant.secondary => shad.SecondaryButton(
onPressed: effectiveOnPressed,
leading: leading,
alignment: alignment,
child: effectiveChild,
),
AppLoadingButtonVariant.primary => AppPrimaryButton(
onPressed: effectiveOnPressed,
leading: leading,
alignment: alignment,
child: effectiveChild,
),
AppLoadingButtonVariant.brand => shad.ButtonStyleOverride(
decoration: (context, states, value) {
final disabled = states.contains(WidgetState.disabled);
final color = loading
? palette.brand
: disabled
? palette.brand.withValues(alpha: 0.38)
: states.contains(WidgetState.pressed)
? Color.alphaBlend(palette.brandForeground.withValues(alpha: 0.12), palette.brand)
: states.contains(WidgetState.hovered)
? Color.alphaBlend(palette.brandForeground.withValues(alpha: 0.08), palette.brand)
: palette.brand;
return BoxDecoration(color: color, borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius));
},
textStyle: (context, states, value) => value.copyWith(
color: states.contains(WidgetState.disabled) && !loading
? palette.brandForeground.withValues(alpha: 0.55)
: palette.brandForeground,
),
iconTheme: (context, states, value) => value.copyWith(
color: states.contains(WidgetState.disabled) && !loading
? palette.brandForeground.withValues(alpha: 0.55)
: palette.brandForeground,
),
child: shad.SecondaryButton(
onPressed: effectiveOnPressed,
leading: leading,
alignment: alignment,
child: effectiveChild,
),
),
};
}
}
class _LoadingIcon extends StatelessWidget {
const _LoadingIcon({required this.variant});
final AppLoadingButtonVariant variant;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final foreground = switch (variant) {
AppLoadingButtonVariant.secondary => palette.textMuted,
AppLoadingButtonVariant.primary => palette.primaryActionForeground,
AppLoadingButtonVariant.brand => palette.brandForeground,
};
final background = switch (variant) {
AppLoadingButtonVariant.secondary => palette.border,
AppLoadingButtonVariant.primary || AppLoadingButtonVariant.brand => foreground.withValues(alpha: 0.24),
};
return Center(
child: SizedBox.square(
dimension: 14,
child: shad.CircularProgressIndicator(size: 14, color: foreground, backgroundColor: background),
),
);
}
}
@@ -0,0 +1,176 @@
import 'package:flutter/material.dart' show Icons;
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../../core/utils/breakpoints.dart';
import '../services/download_directory_picker.dart';
import 'app_tooltip.dart';
enum AppPathPickerButtonStyle { ghost, outline }
class AppPathPickerField extends StatefulWidget {
const AppPathPickerField({
super.key,
required this.controller,
required this.onPick,
this.fieldKey,
this.pickerKey,
this.hintText,
this.desktopWidth,
this.filled,
this.border,
this.borderRadius,
this.padding,
this.onChanged,
this.pickerButtonStyle = AppPathPickerButtonStyle.ghost,
}) : platformDownloadDirectory = false,
onDirectoryPicked = null,
allowAndroidEditing = false;
const AppPathPickerField.downloadDirectory({
super.key,
required this.controller,
this.fieldKey,
this.pickerKey,
this.hintText,
this.desktopWidth,
this.onDirectoryPicked,
this.allowAndroidEditing = false,
this.filled,
this.border,
this.borderRadius,
this.padding,
this.onChanged,
this.pickerButtonStyle = AppPathPickerButtonStyle.outline,
}) : onPick = null,
platformDownloadDirectory = true;
final TextEditingController controller;
final VoidCallback? onPick;
final Key? fieldKey;
final Key? pickerKey;
final String? hintText;
final double? desktopWidth;
final bool? filled;
final Border? border;
final BorderRadiusGeometry? borderRadius;
final EdgeInsetsGeometry? padding;
final ValueChanged<String>? onChanged;
final AppPathPickerButtonStyle pickerButtonStyle;
final bool platformDownloadDirectory;
final ValueChanged<String>? onDirectoryPicked;
final bool allowAndroidEditing;
@override
State<AppPathPickerField> createState() => _AppPathPickerFieldState();
}
class _AppPathPickerFieldState extends State<AppPathPickerField> {
late String _tooltipPath = widget.controller.text.trim();
@override
void initState() {
super.initState();
widget.controller.addListener(_syncTooltipPath);
}
@override
void didUpdateWidget(covariant AppPathPickerField oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) {
oldWidget.controller.removeListener(_syncTooltipPath);
widget.controller.addListener(_syncTooltipPath);
_tooltipPath = widget.controller.text.trim();
}
}
@override
void dispose() {
widget.controller.removeListener(_syncTooltipPath);
super.dispose();
}
void _syncTooltipPath([String? value]) {
final path = (value ?? widget.controller.text).trim();
if (path == _tooltipPath || !mounted) return;
setState(() => _tooltipPath = path);
}
Future<void> _pickPlatformDirectory() async {
final path = await DownloadDirectoryPicker.pick(context, currentPath: widget.controller.text.trim());
if (!mounted || path == null || path.isEmpty || path == widget.controller.text) return;
widget.controller.text = path;
_syncTooltipPath(path);
widget.onDirectoryPicked?.call(path);
}
@override
Widget build(BuildContext context) {
final desktop = MediaQuery.sizeOf(context).width >= Breakpoints.mobile;
final onPick = widget.platformDownloadDirectory
? (DownloadDirectoryPicker.canPick ? _pickPlatformDirectory : null)
: widget.onPick;
return SizedBox(
width: desktop ? widget.desktopWidth : double.infinity,
child: Row(
children: [
Expanded(
child: MouseRegion(
onEnter: (_) => _syncTooltipPath(),
child: AppTooltip(
message: _tooltipPath,
child: shad.TextField(
key: widget.fieldKey,
controller: widget.controller,
hintText: widget.hintText,
readOnly:
widget.platformDownloadDirectory &&
!DownloadDirectoryPicker.canEditManually(allowAndroidEditing: widget.allowAndroidEditing),
filled: widget.filled,
border: widget.border,
borderRadius: widget.borderRadius,
padding: widget.padding,
onChanged: widget.onChanged,
features: [
if (onPick != null && widget.pickerButtonStyle == AppPathPickerButtonStyle.outline)
_PathPickerSuffixFeature(pickerKey: widget.pickerKey, onPressed: onPick),
],
),
),
),
),
if (onPick != null && widget.pickerButtonStyle == AppPathPickerButtonStyle.ghost) ...[
const SizedBox(width: 2),
shad.GhostButton(
key: widget.pickerKey,
density: shad.ButtonDensity.icon,
onPressed: onPick,
child: const Icon(Icons.folder_open_outlined, size: 17),
),
],
],
),
);
}
}
class _PathPickerSuffixFeature extends shad.InputFeature {
const _PathPickerSuffixFeature({required this.pickerKey, required this.onPressed}) : super(skipFocusTraversal: false);
final Key? pickerKey;
final VoidCallback onPressed;
@override
shad.InputFeatureState createState() => _PathPickerSuffixFeatureState();
}
class _PathPickerSuffixFeatureState extends shad.InputFeatureState<_PathPickerSuffixFeature> {
@override
Iterable<Widget> buildSuffix() sync* {
yield shad.IconButton.outline(
key: feature.pickerKey,
onPressed: feature.onPressed,
icon: const Icon(Icons.folder_open_outlined, size: 17),
);
}
}
@@ -0,0 +1,82 @@
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../theme/app_design_tokens.dart';
import '../theme/app_palette.dart';
class AppPrimaryButton extends StatelessWidget {
const AppPrimaryButton({
super.key,
required this.child,
this.onPressed,
this.leading,
this.trailing,
this.alignment,
this.size = shad.ButtonSize.normal,
this.density = shad.ButtonDensity.normal,
this.shape = shad.ButtonShape.rectangle,
this.disableTransition = false,
});
final Widget child;
final VoidCallback? onPressed;
final Widget? leading;
final Widget? trailing;
final AlignmentGeometry? alignment;
final shad.ButtonSize size;
final shad.ButtonDensity density;
final shad.ButtonShape shape;
final bool disableTransition;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return shad.ButtonStyleOverride(
decoration: (context, states, value) {
return BoxDecoration(
color: _resolveBackground(palette, states),
borderRadius: shape == shad.ButtonShape.circle ? null : BorderRadius.circular(AppDesignTokens.controlRadius),
shape: shape == shad.ButtonShape.circle ? BoxShape.circle : BoxShape.rectangle,
);
},
textStyle: (context, states, value) {
return value.copyWith(color: _resolveForeground(palette, states));
},
iconTheme: (context, states, value) {
return value.copyWith(color: _resolveForeground(palette, states));
},
child: shad.PrimaryButton(
onPressed: onPressed,
leading: leading,
trailing: trailing,
alignment: alignment,
size: size,
density: density,
shape: shape,
disableTransition: disableTransition,
child: child,
),
);
}
Color _resolveBackground(AppPalette palette, Set<WidgetState> states) {
if (states.contains(WidgetState.disabled)) {
return palette.primaryActionBg.withValues(alpha: 0.38);
}
if (states.contains(WidgetState.pressed)) {
return Color.alphaBlend(palette.primaryActionForeground.withValues(alpha: 0.14), palette.primaryActionBg);
}
if (states.contains(WidgetState.hovered)) {
return palette.primaryActionHoverBg;
}
return palette.primaryActionBg;
}
Color _resolveForeground(AppPalette palette, Set<WidgetState> states) {
if (states.contains(WidgetState.disabled)) {
return palette.primaryActionForeground.withValues(alpha: 0.55);
}
return palette.primaryActionForeground;
}
}
@@ -0,0 +1,38 @@
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../theme/app_palette.dart';
enum AppToastType { info, success, error }
/// Shows the application's shared toast presentation.
///
/// Toast width is controlled by the loose global [shad.ToastTheme] constraint:
/// short messages stay compact while long messages wrap before becoming wider
/// than the configured maximum. Errors and normal notices use the same layout.
void showAppToast(BuildContext context, String message, {AppToastType type = AppToastType.info}) {
final palette = AppPalette.of(context);
final borderColor = switch (type) {
AppToastType.error => palette.error.withValues(alpha: 0.55),
AppToastType.success || AppToastType.info => palette.border,
};
shad.showToast(
context: context,
location: shad.ToastLocation.topCenter,
builder: (context, overlay) => Align(
alignment: Alignment.topCenter,
widthFactor: 1,
heightFactor: 1,
child: Container(
key: const ValueKey('app-toast-content'),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
decoration: BoxDecoration(
color: palette.cardBg,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: borderColor),
),
child: Text(message, style: TextStyle(color: palette.textPrimary, fontSize: 13, height: 1.2)),
),
),
);
}
@@ -0,0 +1,18 @@
import 'package:flutter/material.dart' show Tooltip;
import 'package:flutter/widgets.dart';
/// The single product tooltip primitive.
///
/// Flutter's tooltip is used intentionally because the shadcn tooltip does not
/// currently inherit Gopeed's mixed Shadcn/Material theme consistently.
class AppTooltip extends StatelessWidget {
const AppTooltip({super.key, required this.message, required this.child});
final String message;
final Widget child;
@override
Widget build(BuildContext context) {
return Tooltip(message: message, child: child);
}
}
@@ -0,0 +1,2 @@
export 'app_detail_surface_desktop.dart';
export 'app_detail_surface_mobile.dart';
@@ -0,0 +1,124 @@
import 'package:flutter/material.dart' show Colors, Icons;
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../../../l10n/l10n.dart';
import '../../theme/app_design_tokens.dart';
import '../../theme/app_palette.dart';
import '../app_tooltip.dart';
class AppDetailDrawer extends StatelessWidget {
const AppDetailDrawer({
super.key,
required this.open,
required this.title,
required this.onClose,
required this.child,
this.drawerKey,
this.width,
});
final bool open;
final String title;
final VoidCallback onClose;
final Widget child;
final Key? drawerKey;
final double? width;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final light = shad.Theme.of(context).brightness == Brightness.light;
final drawerWidth = width ?? AppDesignTokens.taskDetailsDrawerWidth(MediaQuery.sizeOf(context).width);
return IgnorePointer(
ignoring: !open,
child: Stack(
children: [
AnimatedOpacity(
opacity: open ? 1 : 0,
duration: const Duration(milliseconds: 180),
child: GestureDetector(
onTap: onClose,
child: ColoredBox(color: Colors.black.withValues(alpha: 0.35), child: const SizedBox.expand()),
),
),
Align(
alignment: Alignment.centerRight,
child: AnimatedSlide(
duration: const Duration(milliseconds: 260),
curve: Curves.easeOutCubic,
offset: open ? Offset.zero : const Offset(1, 0),
child: Container(
key: drawerKey,
width: drawerWidth,
decoration: BoxDecoration(
color: light ? palette.cardBg : palette.bg,
border: Border(
left: BorderSide(color: light ? palette.headerDivider : palette.border),
top: BorderSide(color: palette.headerDivider),
),
boxShadow: light
? [
BoxShadow(
color: Colors.black.withValues(alpha: 0.08),
blurRadius: 24,
offset: const Offset(-8, 0),
),
]
: null,
),
child: Column(
children: [
SizedBox(
key: const ValueKey('app-detail-drawer-header'),
height: AppDesignTokens.contentHeaderHeight,
child: DecoratedBox(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: palette.headerDivider)),
),
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 24, end: 16),
child: Row(
children: [
Expanded(
child: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: palette.textPrimary,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(width: 12),
AppTooltip(
message: context.l10n.close,
child: SizedBox.square(
dimension: 28,
child: shad.IconButton.ghost(
key: const ValueKey('app-detail-drawer-close-button'),
size: shad.ButtonSize.xSmall,
onPressed: onClose,
icon: Icon(Icons.close, size: 18, color: palette.textSecondary),
),
),
),
],
),
),
),
),
Expanded(child: open ? child : const SizedBox.shrink()),
],
),
),
),
),
],
),
);
}
}
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart' show Icons;
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../../../l10n/l10n.dart';
import '../../theme/app_palette.dart';
import '../app_tooltip.dart';
class AppDetailPage extends StatelessWidget {
const AppDetailPage({
super.key,
required this.title,
required this.onBack,
required this.child,
this.backgroundColor,
});
final String title;
final VoidCallback onBack;
final Widget child;
final Color? backgroundColor;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final background = backgroundColor ?? palette.bg;
return shad.Scaffold(
backgroundColor: background,
child: ColoredBox(
color: background,
child: Column(
children: [
SafeArea(
bottom: false,
child: Container(
height: 52,
padding: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: palette.border)),
),
child: Row(
children: [
SizedBox(
width: 44,
child: AppTooltip(
message: context.l10n.back,
child: shad.IconButton.ghost(
key: const ValueKey('app-detail-back-button'),
onPressed: onBack,
icon: Icon(Icons.arrow_back, size: 20, color: palette.textPrimary),
),
),
),
Expanded(
child: Text(
title,
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: palette.textPrimary, fontSize: 17, fontWeight: FontWeight.w700),
),
),
const SizedBox(width: 44),
],
),
),
),
Expanded(child: child),
],
),
),
);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,129 @@
import 'package:flutter/widgets.dart';
import '../theme/app_palette.dart';
class GopeedAppMark extends StatelessWidget {
const GopeedAppMark({super.key, this.size = 24});
final double size;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return Semantics(
label: 'Gopeed',
image: true,
child: SizedBox.square(
dimension: size,
child: CustomPaint(
painter: _GopeedAppMarkPainter(
background: palette.primaryActionBg,
foreground: palette.primaryActionForeground,
),
),
),
);
}
}
class _GopeedAppMarkPainter extends CustomPainter {
const _GopeedAppMarkPainter({required this.background, required this.foreground});
final Color background;
final Color foreground;
@override
void paint(Canvas canvas, Size size) {
final side = size.shortestSide;
final bounds = Rect.fromCenter(center: size.center(Offset.zero), width: side, height: side).deflate(side * 0.02);
final circle = Path()..addOval(bounds);
final backgroundPaint = Paint()
..color = background
..isAntiAlias = true;
final foregroundPaint = Paint()
..color = foreground
..isAntiAlias = true;
canvas.drawPath(circle, backgroundPaint);
canvas.save();
canvas.clipPath(circle, doAntiAlias: true);
Offset point(double x, double y) {
return Offset(bounds.left + bounds.width * x, bounds.top + bounds.height * y);
}
final cloud = Path()
..moveTo(point(-0.02, 0.83).dx, point(-0.02, 0.83).dy)
..cubicTo(
point(0.04, 0.78).dx,
point(0.04, 0.78).dy,
point(0.09, 0.75).dx,
point(0.09, 0.75).dy,
point(0.15, 0.73).dx,
point(0.15, 0.73).dy,
)
..cubicTo(
point(0.12, 0.66).dx,
point(0.12, 0.66).dy,
point(0.13, 0.60).dx,
point(0.13, 0.60).dy,
point(0.20, 0.57).dx,
point(0.20, 0.57).dy,
)
..cubicTo(
point(0.27, 0.54).dx,
point(0.27, 0.54).dy,
point(0.31, 0.58).dx,
point(0.31, 0.58).dy,
point(0.35, 0.62).dx,
point(0.35, 0.62).dy,
)
..cubicTo(
point(0.46, 0.42).dx,
point(0.46, 0.42).dy,
point(0.66, 0.40).dx,
point(0.66, 0.40).dy,
point(0.78, 0.50).dx,
point(0.78, 0.50).dy,
)
..cubicTo(
point(0.86, 0.57).dx,
point(0.86, 0.57).dy,
point(0.87, 0.68).dx,
point(0.87, 0.68).dy,
point(0.86, 0.75).dx,
point(0.86, 0.75).dy,
)
..cubicTo(
point(0.92, 0.76).dx,
point(0.92, 0.76).dy,
point(0.98, 0.79).dx,
point(0.98, 0.79).dy,
point(1.03, 0.84).dx,
point(1.03, 0.84).dy,
);
canvas.drawPath(
cloud,
Paint()
..color = foreground
..style = PaintingStyle.stroke
..strokeWidth = side * 0.05
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..isAntiAlias = true,
);
final arrow = Path()
..addRect(Rect.fromPoints(point(0.41, 0.66), point(0.59, 0.86)))
..moveTo(point(0.31, 0.85).dx, point(0.31, 0.85).dy)
..lineTo(point(0.69, 0.85).dx, point(0.69, 0.85).dy)
..lineTo(point(0.50, 1.02).dx, point(0.50, 1.02).dy)
..close();
canvas.drawPath(arrow, foregroundPaint);
canvas.restore();
}
@override
bool shouldRepaint(_GopeedAppMarkPainter oldDelegate) {
return background != oldDelegate.background || foreground != oldDelegate.foreground;
}
}
@@ -0,0 +1,153 @@
import 'package:flutter/material.dart' show Icons;
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
import '../../core/utils/breakpoints.dart';
import '../theme/app_palette.dart';
import 'secondary_navigation_pane.dart';
class ResponsiveMenuItem<T> {
const ResponsiveMenuItem({required this.value, required this.label, required this.icon, this.trailing});
final T value;
final String label;
final IconData icon;
final String? trailing;
}
class ResponsiveMenuLayout<T> extends StatefulWidget {
const ResponsiveMenuLayout({
super.key,
required this.title,
required this.items,
required this.selectedValue,
required this.onSelected,
required this.contentBuilder,
this.mobileContentTitleBuilder,
this.mobileContentVisible = false,
this.onMobileBack,
this.sidebarFooter,
this.mobileBreakpoint = Breakpoints.mobile,
});
final String title;
final List<ResponsiveMenuItem<T>> items;
final T selectedValue;
final ValueChanged<T> onSelected;
final Widget Function(BuildContext context, T selectedValue) contentBuilder;
final String Function(T selectedValue)? mobileContentTitleBuilder;
final bool mobileContentVisible;
final VoidCallback? onMobileBack;
final Widget? sidebarFooter;
final double mobileBreakpoint;
@override
State<ResponsiveMenuLayout<T>> createState() => _ResponsiveMenuLayoutState<T>();
}
class _ResponsiveMenuLayoutState<T> extends State<ResponsiveMenuLayout<T>> {
@override
Widget build(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
final mobile = width < widget.mobileBreakpoint;
if (!mobile) {
return Row(
children: [
SecondaryNavigationPane<T>(
title: widget.title,
items: widget.items
.map(
(item) => SecondaryNavigationPaneItem<T>(
value: item.value,
label: item.label,
icon: item.icon,
trailing: item.trailing,
),
)
.toList(),
selectedValue: widget.selectedValue,
onSelected: widget.onSelected,
footer: widget.sidebarFooter,
),
Expanded(child: widget.contentBuilder(context, widget.selectedValue)),
],
);
}
if (!widget.mobileContentVisible) {
return SafeArea(
bottom: false,
child: SecondaryNavigationPane<T>(
title: widget.title,
items: widget.items
.map(
(item) => SecondaryNavigationPaneItem<T>(
value: item.value,
label: item.label,
icon: item.icon,
trailing: item.trailing,
),
)
.toList(),
selectedValue: widget.selectedValue,
onSelected: widget.onSelected,
footer: widget.sidebarFooter,
mobile: true,
showDisclosure: true,
),
);
}
return SafeArea(
bottom: false,
child: Column(
children: [
_MobileContentHeader(
title: widget.mobileContentTitleBuilder?.call(widget.selectedValue) ?? widget.title,
onBack: widget.onMobileBack ?? () {},
),
Expanded(child: widget.contentBuilder(context, widget.selectedValue)),
],
),
);
}
}
class _MobileContentHeader extends StatelessWidget {
const _MobileContentHeader({required this.title, required this.onBack});
final String title;
final VoidCallback onBack;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return Container(
key: const ValueKey('mobile-content-header'),
height: 56,
decoration: BoxDecoration(
color: palette.bg,
border: Border(bottom: BorderSide(color: palette.border)),
),
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: [
shad.GhostButton(
density: shad.ButtonDensity.icon,
onPressed: onBack,
child: Icon(Icons.arrow_back, size: 18, color: palette.textPrimary),
),
const SizedBox(width: 6),
Expanded(
child: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: palette.textPrimary, fontSize: 16, fontWeight: FontWeight.w800),
),
),
],
),
);
}
}
@@ -0,0 +1,166 @@
import 'package:flutter/widgets.dart';
import '../../core/utils/breakpoints.dart';
import '../theme/app_palette.dart';
import 'secondary_navigation_pane.dart';
class ResponsiveNavigationItem<T> {
const ResponsiveNavigationItem({required this.value, required this.label, this.icon, this.count});
final T value;
final String label;
final IconData? icon;
final int? count;
}
class ResponsiveNavigationLayout<T> extends StatelessWidget {
const ResponsiveNavigationLayout({
super.key,
required this.items,
required this.selectedValue,
required this.onSelected,
required this.child,
required this.desktopTitle,
this.desktopFooter,
this.mobileHeader,
this.mobileBreakpoint = Breakpoints.mobile,
});
final List<ResponsiveNavigationItem<T>> items;
final T selectedValue;
final ValueChanged<T> onSelected;
final Widget child;
final String desktopTitle;
final Widget? desktopFooter;
final Widget? mobileHeader;
final double mobileBreakpoint;
@override
Widget build(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
final mobile = width < mobileBreakpoint;
if (!mobile) {
return Row(
children: [
SecondaryNavigationPane<T>(
title: desktopTitle,
items: items
.map(
(item) => SecondaryNavigationPaneItem<T>(
value: item.value,
label: item.label,
icon: item.icon,
trailing: item.count?.toString(),
),
)
.toList(),
selectedValue: selectedValue,
onSelected: onSelected,
footer: desktopFooter,
),
Expanded(child: child),
],
);
}
return Column(
children: [
?mobileHeader,
_MobileNavigationTabs<T>(
items: items,
selectedValue: selectedValue,
onSelected: onSelected,
reserveTopSafeArea: mobileHeader == null,
),
Expanded(child: child),
],
);
}
}
class _MobileNavigationTabs<T> extends StatelessWidget {
const _MobileNavigationTabs({
required this.items,
required this.selectedValue,
required this.onSelected,
required this.reserveTopSafeArea,
});
final List<ResponsiveNavigationItem<T>> items;
final T selectedValue;
final ValueChanged<T> onSelected;
final bool reserveTopSafeArea;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return Container(
width: double.infinity,
decoration: BoxDecoration(
color: palette.bg,
border: Border(bottom: BorderSide(color: palette.border)),
),
child: SafeArea(
top: reserveTopSafeArea,
bottom: false,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.fromLTRB(16, 10, 16, 10),
child: Container(
padding: const EdgeInsets.all(3),
decoration: BoxDecoration(
color: palette.surfaceSoft,
borderRadius: BorderRadius.circular(6),
border: Border.all(color: palette.border),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
for (final item in items)
_MobileNavigationTab<T>(
item: item,
active: item.value == selectedValue,
onTap: () => onSelected(item.value),
),
],
),
),
),
),
);
}
}
class _MobileNavigationTab<T> extends StatelessWidget {
const _MobileNavigationTab({required this.item, required this.active, required this.onTap});
final ResponsiveNavigationItem<T> item;
final bool active;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final label = item.count == null ? item.label : '${item.label} ${item.count}';
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: AnimatedContainer(
duration: const Duration(milliseconds: 140),
curve: Curves.easeOutCubic,
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
decoration: BoxDecoration(color: active ? palette.cardBg : null, borderRadius: BorderRadius.circular(4)),
child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: active ? palette.textPrimary : palette.textSecondary,
fontSize: 12,
fontWeight: active ? FontWeight.w700 : FontWeight.w500,
),
),
),
);
}
}
@@ -0,0 +1,169 @@
import 'package:flutter/material.dart' show Colors, Icons;
import 'package:flutter/widgets.dart';
import '../../core/window/app_window_chrome.dart';
import '../theme/app_design_tokens.dart';
import '../theme/app_palette.dart';
class SecondaryNavigationPaneItem<T> {
const SecondaryNavigationPaneItem({required this.value, required this.label, this.icon, this.trailing});
final T value;
final String label;
final IconData? icon;
final String? trailing;
}
class SecondaryNavigationPane<T> extends StatelessWidget {
const SecondaryNavigationPane({
super.key,
required this.title,
required this.items,
required this.selectedValue,
required this.onSelected,
this.footer,
this.mobile = false,
this.showDisclosure = false,
this.width = AppDesignTokens.filterSidebarWidth,
});
final String title;
final List<SecondaryNavigationPaneItem<T>> items;
final T selectedValue;
final ValueChanged<T> onSelected;
final Widget? footer;
final bool mobile;
final bool showDisclosure;
final double width;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
return Container(
key: const ValueKey('secondary-navigation-pane'),
width: mobile ? double.infinity : width,
color: palette.sideBg,
padding: EdgeInsets.only(
top: !mobile && AppWindowChrome.reservesHeaderInset ? AppDesignTokens.windowHeaderHeight : 0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: AppDesignTokens.contentHeaderHeight,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
title.toUpperCase(),
style: TextStyle(
color: palette.textMuted,
fontSize: 12,
fontWeight: FontWeight.w700,
letterSpacing: 2.4,
),
),
),
),
),
const SizedBox(height: AppDesignTokens.space8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
for (final (index, item) in items.indexed)
_SecondaryNavigationPaneItem<T>(
key: ValueKey('secondary-navigation-item-$index'),
item: item,
active: item.value == selectedValue,
mobile: mobile,
showDisclosure: showDisclosure,
onTap: () => onSelected(item.value),
),
],
),
),
if (footer != null) ...[const Spacer(), footer!] else const Spacer(),
],
),
);
}
}
class _SecondaryNavigationPaneItem<T> extends StatelessWidget {
const _SecondaryNavigationPaneItem({
super.key,
required this.item,
required this.active,
required this.mobile,
required this.showDisclosure,
required this.onTap,
});
final SecondaryNavigationPaneItem<T> item;
final bool active;
final bool mobile;
final bool showDisclosure;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final content = MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: Container(
constraints: BoxConstraints(minHeight: mobile ? 52 : 0),
margin: EdgeInsets.only(bottom: mobile ? 6 : 4),
padding: EdgeInsets.symmetric(horizontal: mobile ? 14 : 12, vertical: mobile ? 12 : 8),
decoration: BoxDecoration(
color: active ? palette.itemActiveBg : Colors.transparent,
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
),
child: Row(
children: [
if (item.icon != null) ...[
Icon(item.icon, size: mobile ? 20 : 16, color: active ? palette.textPrimary : palette.textSecondary),
SizedBox(width: mobile ? 14 : 12),
],
Expanded(
child: Text(
item.label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: active ? palette.textPrimary : palette.textSecondary,
fontSize: mobile ? 16 : 14,
fontWeight: mobile ? FontWeight.w600 : FontWeight.w500,
),
),
),
if (item.trailing != null)
Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: palette.cardHoverBg,
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
),
child: Text(
item.trailing!,
style: TextStyle(
color: active ? palette.textPrimary : palette.textSecondary,
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
)
else if (showDisclosure)
Icon(Icons.chevron_right, size: mobile ? 19 : 15, color: palette.textMuted),
],
),
),
),
);
return content;
}
}
@@ -0,0 +1,101 @@
import 'package:flutter/widgets.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' hide Column, Expanded, Row;
typedef VirtualTreeItemBuilder<T> = Widget Function(BuildContext context, VirtualTreeEntry<T> entry);
typedef VirtualTreeRowTransitionBuilder<T> =
Widget Function(BuildContext context, VirtualTreeEntry<T> entry, Widget row);
class VirtualTreeEntry<T> {
const VirtualTreeEntry({required this.node, required this.depth});
final TreeItemNode<T> node;
final List<TreeNodeDepth> depth;
}
class VirtualTreeView<T> extends StatelessWidget {
const VirtualTreeView({
super.key,
required this.nodes,
required this.itemBuilder,
this.branchLine = BranchLine.path,
this.padding = const EdgeInsets.all(8),
this.rowHeight = 28,
this.cacheExtent = 280,
this.controller,
this.itemPadding,
this.transitionBuilder,
});
final List<TreeNode<T>> nodes;
final VirtualTreeItemBuilder<T> itemBuilder;
final BranchLine branchLine;
final EdgeInsetsGeometry padding;
final double rowHeight;
final double cacheExtent;
final ScrollController? controller;
final EdgeInsetsGeometry? itemPadding;
final VirtualTreeRowTransitionBuilder<T>? transitionBuilder;
@override
Widget build(BuildContext context) {
final entries = _flattenVisibleNodes(nodes);
final theme = Theme.of(context);
final densityGap = theme.density.baseGap * theme.scaling;
return ListView.builder(
controller: controller,
padding: padding,
cacheExtent: cacheExtent,
itemCount: entries.length,
itemBuilder: (context, index) {
final entry = entries[index];
Widget row = SizedBox(
height: rowHeight,
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (var depthIndex = 1; depthIndex < entry.depth.length; depthIndex++) ...[
SizedBox(width: densityGap),
SizedBox(width: densityGap * 2, child: branchLine.build(context, entry.depth, depthIndex)),
],
Expanded(
child: Padding(
padding: itemPadding ?? EdgeInsets.symmetric(horizontal: densityGap, vertical: densityGap * 0.5),
child: itemBuilder(context, entry),
),
),
],
),
);
final transition = transitionBuilder;
if (transition != null) {
row = transition(context, entry, row);
}
return row;
},
);
}
}
List<VirtualTreeEntry<T>> _flattenVisibleNodes<T>(List<TreeNode<T>> nodes) {
final entries = <VirtualTreeEntry<T>>[];
void walk(List<TreeNode<T>> currentNodes, List<TreeNodeDepth> depth) {
for (var index = 0; index < currentNodes.length; index++) {
final node = currentNodes[index];
if (node is TreeRootNode<T>) {
walk(node.children, depth);
continue;
}
if (node is! TreeItemNode<T>) continue;
final currentDepth = [...depth, TreeNodeDepth(index, currentNodes.length)];
entries.add(VirtualTreeEntry(node: node, depth: currentDepth));
if (node.expanded) {
walk(node.children, currentDepth);
}
}
}
walk(nodes, const []);
return entries;
}
@@ -0,0 +1,310 @@
import 'package:flutter/foundation.dart' show TargetPlatform, defaultTargetPlatform;
import 'package:flutter/material.dart' show Colors;
import 'package:flutter/widgets.dart';
import 'package:window_manager/window_manager.dart';
import '../../../core/window/app_window_chrome.dart';
import '../../theme/app_design_tokens.dart';
import '../../theme/app_palette.dart';
class DesktopWindowHeader extends StatelessWidget {
const DesktopWindowHeader({super.key});
@override
Widget build(BuildContext context) {
if (!AppWindowChrome.usesCustomChrome) {
return const SizedBox.shrink();
}
return SizedBox(
height: AppDesignTokens.windowHeaderHeight,
child: const Row(
children: [
Expanded(child: DragToMoveArea(child: SizedBox.expand())),
WindowCaptionControls(),
],
),
);
}
}
class WindowCaptionControls extends StatefulWidget {
const WindowCaptionControls({super.key});
@override
State<WindowCaptionControls> createState() => _WindowCaptionControlsState();
}
class _WindowCaptionControlsState extends State<WindowCaptionControls> with WindowListener {
static const double _captionGlyphSize = 20;
bool _isMaximized = false;
@override
void initState() {
super.initState();
windowManager.addListener(this);
_refreshState();
}
@override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}
@override
void onWindowMaximize() => _refreshState();
@override
void onWindowUnmaximize() => _refreshState();
Future<void> _refreshState() async {
final value = await windowManager.isMaximized();
if (mounted) {
setState(() => _isMaximized = value);
}
}
@override
Widget build(BuildContext context) {
if (!AppWindowChrome.usesCustomChrome) {
return const SizedBox.shrink();
}
final palette = AppPalette.of(context);
final textColor = palette.textSecondary;
final isLinux = defaultTargetPlatform == TargetPlatform.linux;
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
_CaptionControlButton(
icon: const _MinimizeGlyph(),
foreground: textColor,
size: isLinux ? 28 : 30,
radius: isLinux ? 999 : 4,
background: isLinux ? const Color(0x0DFFFFFF) : Colors.transparent,
hoverBackground: isLinux ? const Color(0x1AE95420) : palette.captionButtonHover,
hoverForeground: textColor,
onPressed: windowManager.minimize,
),
SizedBox(width: isLinux ? 8 : 4),
_CaptionControlButton(
icon: _isMaximized ? const _RestoreGlyph() : const _MaximizeGlyph(),
foreground: textColor,
size: isLinux ? 28 : 30,
radius: isLinux ? 999 : 4,
background: isLinux ? const Color(0x0DFFFFFF) : Colors.transparent,
hoverBackground: isLinux ? const Color(0x1AE95420) : palette.captionButtonHover,
hoverForeground: textColor,
onPressed: _isMaximized ? windowManager.unmaximize : windowManager.maximize,
),
SizedBox(width: isLinux ? 8 : 4),
_CaptionControlButton(
icon: const _CloseGlyph(),
foreground: isLinux ? const Color(0xFFE95420) : textColor,
background: isLinux ? const Color(0x33E95420) : Colors.transparent,
size: isLinux ? 28 : 30,
radius: isLinux ? 999 : 4,
hoverBackground: isLinux ? const Color(0xFFE95420) : const Color(0xFFE81123),
hoverForeground: const Color(0xFFFFFFFF),
onPressed: windowManager.close,
),
],
);
}
}
class _CaptionControlButton extends StatefulWidget {
const _CaptionControlButton({
required this.icon,
required this.foreground,
required this.onPressed,
required this.size,
required this.radius,
required this.background,
this.hoverBackground,
this.hoverForeground,
});
final Widget icon;
final Color foreground;
final VoidCallback onPressed;
final double size;
final double radius;
final Color background;
final Color? hoverBackground;
final Color? hoverForeground;
@override
State<_CaptionControlButton> createState() => _CaptionControlButtonState();
}
class _CaptionControlButtonState extends State<_CaptionControlButton> {
bool _hovered = false;
@override
Widget build(BuildContext context) {
final palette = AppPalette.of(context);
final background = _hovered ? (widget.hoverBackground ?? palette.captionButtonHover) : widget.background;
final foreground = _hovered ? (widget.hoverForeground ?? widget.foreground) : widget.foreground;
return MouseRegion(
onEnter: (_) => setState(() => _hovered = true),
onExit: (_) => setState(() => _hovered = false),
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: widget.onPressed,
child: Container(
width: widget.size,
height: widget.size,
alignment: Alignment.center,
decoration: BoxDecoration(color: background, borderRadius: BorderRadius.circular(widget.radius)),
child: IconTheme(
data: IconThemeData(color: foreground),
child: Center(child: widget.icon),
),
),
),
);
}
}
class _MinimizeGlyph extends StatelessWidget {
const _MinimizeGlyph();
@override
Widget build(BuildContext context) {
final color = IconTheme.of(context).color ?? Colors.white;
final size = _WindowCaptionControlsState._captionGlyphSize;
return SizedBox(
width: size,
height: size,
child: Center(
child: Container(
width: size * 0.72,
height: size <= 12 ? 1.2 : 1.6,
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(999)),
),
),
);
}
}
class _MaximizeGlyph extends StatelessWidget {
const _MaximizeGlyph();
@override
Widget build(BuildContext context) {
final color = IconTheme.of(context).color ?? Colors.white;
final size = _WindowCaptionControlsState._captionGlyphSize;
final boxSize = size * 0.62;
return SizedBox(
width: size,
height: size,
child: Center(
child: Container(
width: boxSize,
height: boxSize,
decoration: BoxDecoration(
border: Border.all(color: color, width: size <= 12 ? 0.9 : 0.95),
borderRadius: BorderRadius.circular(1),
),
),
),
);
}
}
class _RestoreGlyph extends StatelessWidget {
const _RestoreGlyph();
@override
Widget build(BuildContext context) {
final color = IconTheme.of(context).color ?? Colors.white;
final size = _WindowCaptionControlsState._captionGlyphSize;
final boxSize = size * 0.56;
final topBoxLeft = size * 0.40;
final topBoxTop = size * 0.16;
final bottomBoxLeft = size * 0.16;
final bottomBoxTop = size * 0.40;
final borderWidth = size <= 12 ? 1.0 : 1.15;
return SizedBox(
width: size,
height: size,
child: Stack(
children: [
Positioned(
left: topBoxLeft,
top: topBoxTop,
child: Container(
width: boxSize,
height: boxSize,
decoration: BoxDecoration(
border: Border.all(color: color, width: borderWidth),
borderRadius: BorderRadius.circular(1),
),
),
),
Positioned(
left: bottomBoxLeft,
top: bottomBoxTop,
child: Container(
width: boxSize,
height: boxSize,
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(color: color, width: borderWidth),
borderRadius: BorderRadius.circular(1),
),
),
),
],
),
);
}
}
class _CloseGlyph extends StatelessWidget {
const _CloseGlyph();
@override
Widget build(BuildContext context) {
final color = IconTheme.of(context).color ?? Colors.white;
return SizedBox(
width: _WindowCaptionControlsState._captionGlyphSize,
height: _WindowCaptionControlsState._captionGlyphSize,
child: CustomPaint(painter: _CrossPainter(color)),
);
}
}
class _CrossPainter extends CustomPainter {
const _CrossPainter(this.color);
final Color color;
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = color
..strokeWidth = size.width <= 12 ? 1.2 : 1.8
..strokeCap = StrokeCap.round;
canvas.drawLine(
Offset(size.width * 0.28, size.height * 0.28),
Offset(size.width * 0.72, size.height * 0.72),
paint,
);
canvas.drawLine(
Offset(size.width * 0.72, size.height * 0.28),
Offset(size.width * 0.28, size.height * 0.72),
paint,
);
}
@override
bool shouldRepaint(covariant _CrossPainter oldDelegate) {
return oldDelegate.color != color;
}
}