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,224 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../../shared/theme/app_palette.dart';
|
||||
import '../../../../shared/widgets/app_loading_button.dart';
|
||||
import '../../../../util/package_info.dart';
|
||||
import '../../../../util/updater.dart';
|
||||
import '../../../../util/util.dart';
|
||||
import '../../../../l10n/l10n.dart';
|
||||
|
||||
typedef StartAppUpdate = Future<void> Function(VersionInfo versionInfo, UpdateProgressCallback onProgress);
|
||||
|
||||
Future<void> showAppUpdateDialog(
|
||||
BuildContext context, {
|
||||
required VersionInfo versionInfo,
|
||||
required StartAppUpdate onUpdate,
|
||||
}) async {
|
||||
final overlay = const shad.DialogOverlayHandler().show<void>(
|
||||
context: context,
|
||||
alignment: Alignment.center,
|
||||
barrierDismissable: false,
|
||||
builder: (dialogContext) {
|
||||
var updating = false;
|
||||
var received = 0;
|
||||
var total = 0;
|
||||
String? errorMessage;
|
||||
|
||||
return StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) {
|
||||
final palette = AppPalette.of(dialogContext);
|
||||
final availableWidth = MediaQuery.sizeOf(dialogContext).width - 104;
|
||||
final dialogWidth = availableWidth.clamp(260.0, 380.0);
|
||||
final releaseNotes = localizedReleaseNotes(
|
||||
versionInfo.changeLog,
|
||||
Localizations.localeOf(dialogContext).languageCode,
|
||||
);
|
||||
final progress = total > 0 ? (received / total).clamp(0.0, 1.0) : null;
|
||||
|
||||
Future<void> update() async {
|
||||
setDialogState(() {
|
||||
updating = true;
|
||||
errorMessage = null;
|
||||
});
|
||||
try {
|
||||
await onUpdate(versionInfo, (nextReceived, nextTotal) {
|
||||
if (!dialogContext.mounted) return;
|
||||
setDialogState(() {
|
||||
received = nextReceived;
|
||||
total = nextTotal;
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
if (!dialogContext.mounted) return;
|
||||
setDialogState(() {
|
||||
updating = false;
|
||||
errorMessage = dialogContext.l10n.updateFailed;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return shad.AlertDialog(
|
||||
padding: const EdgeInsets.all(20),
|
||||
title: SizedBox(
|
||||
width: dialogWidth,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
dialogContext.l10n.newVersionAvailable,
|
||||
key: const ValueKey('app-update-heading'),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
'$appVersion → ${versionInfo.version}',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 12, fontWeight: FontWeight.w400),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
content: SizedBox(
|
||||
key: const ValueKey('app-update-dialog'),
|
||||
width: dialogWidth,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
dialogContext.l10n.releaseNotes,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 12, fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 210),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: _ReleaseNotes(
|
||||
notes: releaseNotes.isEmpty ? dialogContext.l10n.noReleaseNotes : releaseNotes,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (updating) ...[
|
||||
const SizedBox(height: 16),
|
||||
shad.LinearProgressIndicator(
|
||||
value: progress,
|
||||
minHeight: 5,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
color: palette.brand,
|
||||
backgroundColor: palette.progressTrack,
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
progress == null
|
||||
? dialogContext.l10n.preparingDownload
|
||||
: '${(progress * 100).toStringAsFixed(0)}%',
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 11),
|
||||
),
|
||||
const Spacer(),
|
||||
if (total > 0)
|
||||
Text(
|
||||
'${Util.fmtByte(received)} / ${Util.fmtByte(total)}',
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (errorMessage != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 15, color: palette.error),
|
||||
const SizedBox(width: 6),
|
||||
Text(errorMessage!, style: TextStyle(color: palette.error, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 18),
|
||||
Wrap(
|
||||
key: const ValueKey('app-update-actions'),
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
shad.SecondaryButton(
|
||||
onPressed: updating ? null : () => unawaited(shad.closeOverlay(dialogContext)),
|
||||
child: Text(dialogContext.l10n.newVersionLater),
|
||||
),
|
||||
AppLoadingButton(
|
||||
onPressed: () => unawaited(update()),
|
||||
loading: updating,
|
||||
variant: AppLoadingButtonVariant.primary,
|
||||
icon: const Icon(Icons.system_update_alt_outlined, size: 17),
|
||||
child: Text(dialogContext.l10n.newVersionUpdate),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
await overlay.future;
|
||||
}
|
||||
|
||||
class _ReleaseNotes extends StatelessWidget {
|
||||
const _ReleaseNotes({required this.notes});
|
||||
|
||||
final String notes;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final lines = notes
|
||||
.split('\n')
|
||||
.map((line) => line.trimRight())
|
||||
.where((line) => line.trim().isNotEmpty)
|
||||
.where((line) => !RegExp(r'^#\s+(Release notes|更新日志)\s*$', caseSensitive: false).hasMatch(line.trim()));
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final line in lines) ...[
|
||||
if (line.startsWith('#'))
|
||||
Text(
|
||||
_plainMarkdown(line.replaceFirst(RegExp(r'^#+\s*'), '')),
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 13, fontWeight: FontWeight.w700),
|
||||
)
|
||||
else if (line.trimLeft().startsWith('- '))
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('• ', style: TextStyle(color: palette.textSecondary, fontSize: 12, height: 1.45)),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_plainMarkdown(line.trimLeft().substring(2).replaceFirst(RegExp(r'\s+@[\w-]+\s+\(#\d+\)\s*$'), '')),
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 12, height: 1.45),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
else
|
||||
Text(_plainMarkdown(line), style: TextStyle(color: palette.textSecondary, fontSize: 12, height: 1.45)),
|
||||
const SizedBox(height: 7),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _plainMarkdown(String value) {
|
||||
return value
|
||||
.replaceAllMapped(RegExp(r'\[([^\]]+)\]\([^\)]+\)'), (match) => match.group(1) ?? '')
|
||||
.replaceAll(RegExp(r'\*\*|__|`'), '');
|
||||
}
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
import 'package:flutter/material.dart' show Divider, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../../api/model/downloader_config.dart';
|
||||
import '../../../../core/utils/breakpoints.dart';
|
||||
import '../../../../shared/theme/app_design_tokens.dart';
|
||||
import '../../../../shared/theme/app_palette.dart';
|
||||
import '../../../../shared/widgets/app_path_picker_field.dart';
|
||||
import '../../../../shared/widgets/app_primary_button.dart';
|
||||
import '../../../../l10n/l10n.dart';
|
||||
|
||||
class DownloadCategoryDraft {
|
||||
const DownloadCategoryDraft({required this.name, required this.path});
|
||||
|
||||
final String name;
|
||||
final String path;
|
||||
}
|
||||
|
||||
class DownloadCategoriesControl extends StatelessWidget {
|
||||
const DownloadCategoriesControl({
|
||||
super.key,
|
||||
required this.categories,
|
||||
required this.displayName,
|
||||
required this.onAdd,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
final List<DownloadCategory> categories;
|
||||
final String Function(DownloadCategory category) displayName;
|
||||
final VoidCallback onAdd;
|
||||
final ValueChanged<DownloadCategory> onEdit;
|
||||
final ValueChanged<DownloadCategory> onDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final desktop = MediaQuery.sizeOf(context).width >= Breakpoints.mobile;
|
||||
final visibleCategories = categories.where((category) => !category.isDeleted).toList(growable: false);
|
||||
final palette = AppPalette.of(context);
|
||||
|
||||
return SizedBox(
|
||||
key: const ValueKey('download-categories-editor'),
|
||||
width: desktop ? AppDesignTokens.settingsFormControlWidth : double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (var index = 0; index < visibleCategories.length; index++) ...[
|
||||
if (index > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Divider(color: palette.border),
|
||||
),
|
||||
_CategoryRow(
|
||||
category: visibleCategories[index],
|
||||
name: displayName(visibleCategories[index]),
|
||||
onEdit: () => onEdit(visibleCategories[index]),
|
||||
onDelete: () => onDelete(visibleCategories[index]),
|
||||
),
|
||||
],
|
||||
if (visibleCategories.isNotEmpty) const SizedBox(height: 10),
|
||||
Align(
|
||||
alignment: desktop ? Alignment.centerRight : Alignment.centerLeft,
|
||||
child: shad.SecondaryButton(
|
||||
key: const ValueKey('add-download-category'),
|
||||
onPressed: onAdd,
|
||||
leading: const Icon(Icons.add, size: 17),
|
||||
child: Text(context.l10n.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategoryRow extends StatelessWidget {
|
||||
const _CategoryRow({required this.category, required this.name, required this.onEdit, required this.onDelete});
|
||||
|
||||
final DownloadCategory category;
|
||||
final String name;
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return Row(
|
||||
key: ValueKey('download-category-${category.nameKey ?? category.name}-${category.path}'),
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 13, fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
category.path,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
shad.GhostButton(
|
||||
key: ValueKey('edit-download-category-${category.nameKey ?? category.name}'),
|
||||
density: shad.ButtonDensity.icon,
|
||||
onPressed: onEdit,
|
||||
child: const Icon(Icons.edit_outlined, size: 17),
|
||||
),
|
||||
shad.GhostButton(
|
||||
key: ValueKey('delete-download-category-${category.nameKey ?? category.name}'),
|
||||
density: shad.ButtonDensity.icon,
|
||||
onPressed: onDelete,
|
||||
child: const Icon(Icons.delete_outline, size: 17),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<DownloadCategoryDraft?> showDownloadCategoryDialog(
|
||||
BuildContext context, {
|
||||
DownloadCategory? category,
|
||||
required String initialName,
|
||||
required String initialPath,
|
||||
}) async {
|
||||
final nameController = TextEditingController(text: initialName);
|
||||
final pathController = TextEditingController(text: category?.path ?? initialPath);
|
||||
String? validationMessage;
|
||||
|
||||
final overlay = const shad.DialogOverlayHandler().show<DownloadCategoryDraft?>(
|
||||
context: context,
|
||||
alignment: Alignment.center,
|
||||
barrierDismissable: false,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) {
|
||||
final palette = AppPalette.of(dialogContext);
|
||||
|
||||
void submit() {
|
||||
final name = nameController.text.trim();
|
||||
final path = pathController.text.trim();
|
||||
if (name.isEmpty || path.isEmpty) {
|
||||
setDialogState(() => validationMessage = dialogContext.l10n.categoryFieldsRequired);
|
||||
return;
|
||||
}
|
||||
shad.closeOverlay(dialogContext, DownloadCategoryDraft(name: name, path: path));
|
||||
}
|
||||
|
||||
return shad.AlertDialog(
|
||||
title: Text(category == null ? dialogContext.l10n.addCategory : dialogContext.l10n.editCategory),
|
||||
content: SizedBox(
|
||||
key: const ValueKey('download-category-dialog'),
|
||||
width: (MediaQuery.sizeOf(dialogContext).width - 64).clamp(260.0, 420.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(dialogContext.l10n.categoryName, style: TextStyle(color: palette.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 6),
|
||||
shad.TextField(key: const ValueKey('download-category-name'), controller: nameController),
|
||||
const SizedBox(height: 14),
|
||||
Text(dialogContext.l10n.categoryPath, style: TextStyle(color: palette.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 6),
|
||||
AppPathPickerField.downloadDirectory(
|
||||
fieldKey: const ValueKey('download-category-path'),
|
||||
controller: pathController,
|
||||
desktopWidth: AppDesignTokens.settingsFormControlWidth,
|
||||
allowAndroidEditing: true,
|
||||
),
|
||||
if (validationMessage != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(validationMessage!, style: TextStyle(color: palette.error, fontSize: 12)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
shad.SecondaryButton(
|
||||
onPressed: () => shad.closeOverlay(dialogContext),
|
||||
child: Text(dialogContext.l10n.cancel),
|
||||
),
|
||||
AppPrimaryButton(onPressed: submit, child: Text(dialogContext.l10n.confirm)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
return await overlay.future;
|
||||
} finally {
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
nameController.dispose();
|
||||
pathController.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> showDeleteDownloadCategoryDialog(BuildContext context, String name) async {
|
||||
final overlay = const shad.DialogOverlayHandler().show<bool>(
|
||||
context: context,
|
||||
alignment: Alignment.center,
|
||||
barrierDismissable: false,
|
||||
builder: (dialogContext) => shad.AlertDialog(
|
||||
title: Text(dialogContext.l10n.deleteCategoryTitle),
|
||||
content: Text(dialogContext.l10n.confirmDeleteNamed(name)),
|
||||
actions: [
|
||||
shad.SecondaryButton(
|
||||
onPressed: () => shad.closeOverlay(dialogContext, false),
|
||||
child: Text(dialogContext.l10n.cancel),
|
||||
),
|
||||
shad.DestructiveButton(
|
||||
onPressed: () => shad.closeOverlay(dialogContext, true),
|
||||
child: Text(dialogContext.l10n.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return await overlay.future ?? false;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../../shared/theme/app_design_tokens.dart';
|
||||
|
||||
class SettingsContentFrame extends StatelessWidget {
|
||||
const SettingsContentFrame({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppDesignTokens.space24),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: AppDesignTokens.settingsContentMaxWidth),
|
||||
child: SizedBox(width: double.infinity, child: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../../core/utils/breakpoints.dart';
|
||||
import '../../../../shared/theme/app_design_tokens.dart';
|
||||
import '../../../../shared/theme/app_palette.dart';
|
||||
|
||||
class SettingsItem extends StatelessWidget {
|
||||
const SettingsItem({super.key, required this.title, required this.child, this.subtitle});
|
||||
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final desktop = MediaQuery.sizeOf(context).width >= Breakpoints.mobile;
|
||||
if (desktop) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
const leadingSpace = 2.0;
|
||||
const columnGap = AppDesignTokens.space24;
|
||||
final maxControlWidth =
|
||||
(constraints.maxWidth - leadingSpace - columnGap - AppDesignTokens.settingsItemMinLabelWidth).clamp(
|
||||
0.0,
|
||||
double.infinity,
|
||||
);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(width: leadingSpace),
|
||||
Expanded(
|
||||
child: _SettingsItemLabel(title: title, subtitle: subtitle),
|
||||
),
|
||||
const SizedBox(width: columnGap),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: maxControlWidth),
|
||||
child: child,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_SettingsItemLabel(title: title, subtitle: subtitle),
|
||||
const SizedBox(height: 10),
|
||||
Align(alignment: Alignment.centerLeft, child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingsItemLabel extends StatelessWidget {
|
||||
const _SettingsItemLabel({required this.title, this.subtitle});
|
||||
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final subtitleText = subtitle?.trim();
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 13, fontWeight: FontWeight.w700),
|
||||
),
|
||||
if (subtitleText != null && subtitleText.isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(subtitleText, style: TextStyle(color: palette.textSecondary, fontSize: 12, height: 1.3)),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../../core/utils/breakpoints.dart';
|
||||
import '../../../../l10n/l10n.dart';
|
||||
|
||||
class SettingsLanguageSelect extends StatelessWidget {
|
||||
const SettingsLanguageSelect({super.key, required this.value, required this.onChanged});
|
||||
|
||||
final String value;
|
||||
final ValueChanged<String> onChanged;
|
||||
|
||||
static List<Locale> get supportedLocales => AppLocalizations.supportedLocales;
|
||||
|
||||
static Set<String> get supportedValues => supportedLocales.map(localeConfigValue).toSet();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isMobile = MediaQuery.sizeOf(context).width < Breakpoints.mobile;
|
||||
final popupMaxHeight = isMobile ? math.min(MediaQuery.sizeOf(context).height * 0.62, 420.0) : 240.0;
|
||||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = isMobile || constraints.maxWidth < 220 ? constraints.maxWidth : 220.0;
|
||||
return shad.Select<String>(
|
||||
key: const ValueKey('settings-language-select'),
|
||||
value: value,
|
||||
constraints: BoxConstraints.tightFor(width: width, height: isMobile ? 44 : 36),
|
||||
popupConstraints: BoxConstraints(maxHeight: popupMaxHeight),
|
||||
itemBuilder: (context, selectedValue) => Text(_labelFor(context, selectedValue)),
|
||||
popup: (context) => shad.SelectPopup<String>(
|
||||
items: shad.SelectItemList(
|
||||
children: [
|
||||
shad.SelectItemButton<String>(
|
||||
value: 'system',
|
||||
child: _LanguageOptionLabel(label: context.l10n.followSystem, mobile: isMobile),
|
||||
),
|
||||
for (final locale in supportedLocales)
|
||||
shad.SelectItemButton<String>(
|
||||
value: localeConfigValue(locale),
|
||||
child: _LanguageOptionLabel(label: lookupAppLocalizations(locale).label, mobile: isMobile),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
onChanged: (selectedValue) {
|
||||
if (selectedValue != null) {
|
||||
onChanged(selectedValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String _labelFor(BuildContext context, String selectedValue) {
|
||||
if (selectedValue == 'system') return context.l10n.followSystem;
|
||||
final locale = localeFromConfig(selectedValue);
|
||||
if (locale != null && supportedValues.contains(localeConfigValue(locale))) {
|
||||
return lookupAppLocalizations(locale).label;
|
||||
}
|
||||
return context.l10n.followSystem;
|
||||
}
|
||||
}
|
||||
|
||||
class _LanguageOptionLabel extends StatelessWidget {
|
||||
const _LanguageOptionLabel({required this.label, required this.mobile});
|
||||
|
||||
final String label;
|
||||
final bool mobile;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: mobile ? 28 : 20,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(label, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
import 'package:flutter/material.dart' show Divider, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../../api/model/downloader_config.dart';
|
||||
import '../../../../core/utils/breakpoints.dart';
|
||||
import '../../../../shared/theme/app_design_tokens.dart';
|
||||
import '../../../../shared/theme/app_palette.dart';
|
||||
import '../../../../shared/widgets/app_loading_button.dart';
|
||||
import '../../../../shared/widgets/app_path_picker_field.dart';
|
||||
import '../../../../shared/widgets/app_primary_button.dart';
|
||||
import '../../../../l10n/l10n.dart';
|
||||
|
||||
class SettingsListEntry {
|
||||
const SettingsListEntry({required this.id, required this.title, this.subtitle});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
}
|
||||
|
||||
class SettingsListEditor extends StatelessWidget {
|
||||
const SettingsListEditor({
|
||||
super.key,
|
||||
required this.entries,
|
||||
required this.onAdd,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
this.addLabel,
|
||||
this.addButtonKey,
|
||||
});
|
||||
|
||||
final List<SettingsListEntry> entries;
|
||||
final VoidCallback onAdd;
|
||||
final ValueChanged<int> onEdit;
|
||||
final ValueChanged<int> onDelete;
|
||||
final String? addLabel;
|
||||
final Key? addButtonKey;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final desktop = MediaQuery.sizeOf(context).width >= Breakpoints.mobile;
|
||||
final palette = AppPalette.of(context);
|
||||
return SizedBox(
|
||||
width: desktop ? AppDesignTokens.settingsFormControlWidth : double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (var index = 0; index < entries.length; index++) ...[
|
||||
if (index > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Divider(color: palette.border),
|
||||
),
|
||||
Row(
|
||||
key: ValueKey('settings-list-entry-${entries[index].id}'),
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
entries[index].title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 13),
|
||||
),
|
||||
if (entries[index].subtitle case final subtitle?) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
subtitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 11),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
shad.GhostButton(
|
||||
key: ValueKey('edit-settings-list-${entries[index].id}'),
|
||||
density: shad.ButtonDensity.icon,
|
||||
onPressed: () => onEdit(index),
|
||||
child: const Icon(Icons.edit_outlined, size: 17),
|
||||
),
|
||||
shad.GhostButton(
|
||||
key: ValueKey('delete-settings-list-${entries[index].id}'),
|
||||
density: shad.ButtonDensity.icon,
|
||||
onPressed: () => onDelete(index),
|
||||
child: const Icon(Icons.delete_outline, size: 17),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (entries.isNotEmpty) const SizedBox(height: 10),
|
||||
Align(
|
||||
alignment: desktop ? Alignment.centerRight : Alignment.centerLeft,
|
||||
child: shad.SecondaryButton(
|
||||
key: addButtonKey,
|
||||
onPressed: onAdd,
|
||||
leading: const Icon(Icons.add, size: 17),
|
||||
child: Text(addLabel ?? context.l10n.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> showTextSettingDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String fieldLabel,
|
||||
String initialValue = '',
|
||||
bool requireHttpUrl = false,
|
||||
Future<String?> Function()? pickPath,
|
||||
Future<void> Function(String value)? onTest,
|
||||
}) async {
|
||||
final controller = TextEditingController(text: initialValue);
|
||||
String? validationMessage;
|
||||
bool testing = false;
|
||||
String? testMessage;
|
||||
bool? testSucceeded;
|
||||
final overlay = const shad.DialogOverlayHandler().show<String?>(
|
||||
context: context,
|
||||
alignment: Alignment.center,
|
||||
barrierDismissable: false,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) {
|
||||
final palette = AppPalette.of(dialogContext);
|
||||
|
||||
String? validate() {
|
||||
final value = controller.text.trim();
|
||||
if (value.isEmpty) return dialogContext.l10n.fieldRequired(fieldLabel);
|
||||
if (requireHttpUrl && !(value.startsWith('http://') || value.startsWith('https://'))) {
|
||||
return dialogContext.l10n.urlInvalid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> test() async {
|
||||
final error = validate();
|
||||
if (error != null) {
|
||||
setDialogState(() => validationMessage = error);
|
||||
return;
|
||||
}
|
||||
setDialogState(() {
|
||||
testing = true;
|
||||
validationMessage = null;
|
||||
testMessage = null;
|
||||
testSucceeded = null;
|
||||
});
|
||||
try {
|
||||
await onTest!(controller.text.trim());
|
||||
if (dialogContext.mounted) {
|
||||
setDialogState(() {
|
||||
testMessage = dialogContext.l10n.webhookTestSuccess;
|
||||
testSucceeded = true;
|
||||
});
|
||||
}
|
||||
} catch (_) {
|
||||
if (dialogContext.mounted) {
|
||||
setDialogState(() {
|
||||
testMessage = dialogContext.l10n.webhookTestFail;
|
||||
testSucceeded = false;
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
if (dialogContext.mounted) setDialogState(() => testing = false);
|
||||
}
|
||||
}
|
||||
|
||||
return shad.AlertDialog(
|
||||
title: Text(title),
|
||||
content: SizedBox(
|
||||
width: (MediaQuery.sizeOf(dialogContext).width - 64).clamp(260.0, 420.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(fieldLabel, style: TextStyle(color: palette.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 6),
|
||||
if (pickPath == null)
|
||||
shad.TextField(controller: controller)
|
||||
else
|
||||
AppPathPickerField(
|
||||
controller: controller,
|
||||
desktopWidth: AppDesignTokens.settingsFormControlWidth,
|
||||
onPick: () async {
|
||||
final path = await pickPath();
|
||||
if (path != null && path.isNotEmpty) controller.text = path;
|
||||
},
|
||||
),
|
||||
if (validationMessage != null || testMessage != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
validationMessage ?? testMessage!,
|
||||
style: TextStyle(
|
||||
color: validationMessage != null
|
||||
? palette.error
|
||||
: testSucceeded == true
|
||||
? palette.success
|
||||
: palette.error,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
if (onTest != null)
|
||||
AppLoadingButton(
|
||||
onPressed: test,
|
||||
loading: testing,
|
||||
icon: const Icon(Icons.send_outlined, size: 16),
|
||||
child: Text(dialogContext.l10n.webhookTest),
|
||||
),
|
||||
shad.SecondaryButton(
|
||||
onPressed: () => shad.closeOverlay(dialogContext),
|
||||
child: Text(dialogContext.l10n.cancel),
|
||||
),
|
||||
AppPrimaryButton(
|
||||
onPressed: () {
|
||||
final error = validate();
|
||||
if (error != null) {
|
||||
setDialogState(() => validationMessage = error);
|
||||
return;
|
||||
}
|
||||
shad.closeOverlay(dialogContext, controller.text.trim());
|
||||
},
|
||||
child: Text(dialogContext.l10n.confirm),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
try {
|
||||
return await overlay.future;
|
||||
} finally {
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
controller.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class GithubMirrorDraft {
|
||||
const GithubMirrorDraft({required this.type, required this.url});
|
||||
|
||||
final GithubMirrorType type;
|
||||
final String url;
|
||||
}
|
||||
|
||||
Future<GithubMirrorDraft?> showGithubMirrorDialog(BuildContext context, {GithubMirror? mirror}) async {
|
||||
var selectedType = mirror?.type ?? GithubMirrorType.jsdelivr;
|
||||
final controller = TextEditingController(text: mirror?.url ?? '');
|
||||
String? validationMessage;
|
||||
final overlay = const shad.DialogOverlayHandler().show<GithubMirrorDraft?>(
|
||||
context: context,
|
||||
alignment: Alignment.center,
|
||||
barrierDismissable: false,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) {
|
||||
final palette = AppPalette.of(dialogContext);
|
||||
return shad.AlertDialog(
|
||||
title: Text(mirror == null ? dialogContext.l10n.addGithubMirror : dialogContext.l10n.editGithubMirror),
|
||||
content: SizedBox(
|
||||
width: (MediaQuery.sizeOf(dialogContext).width - 64).clamp(260.0, 420.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(dialogContext.l10n.githubMirrorType, style: TextStyle(color: palette.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 6),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
for (final type in GithubMirrorType.values)
|
||||
shad.SecondaryButton(
|
||||
onPressed: () => setDialogState(() => selectedType = type),
|
||||
leading: selectedType == type ? const Icon(Icons.check, size: 15) : null,
|
||||
child: Text(type.name),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Text(dialogContext.l10n.githubMirrorUrl, style: TextStyle(color: palette.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 6),
|
||||
shad.TextField(controller: controller),
|
||||
if (validationMessage != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(validationMessage!, style: TextStyle(color: palette.error, fontSize: 12)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
shad.SecondaryButton(
|
||||
onPressed: () => shad.closeOverlay(dialogContext),
|
||||
child: Text(dialogContext.l10n.cancel),
|
||||
),
|
||||
AppPrimaryButton(
|
||||
onPressed: () {
|
||||
final value = controller.text.trim();
|
||||
if (value.isEmpty || !(value.startsWith('http://') || value.startsWith('https://'))) {
|
||||
setDialogState(() => validationMessage = dialogContext.l10n.urlInvalid);
|
||||
return;
|
||||
}
|
||||
shad.closeOverlay(dialogContext, GithubMirrorDraft(type: selectedType, url: value));
|
||||
},
|
||||
child: Text(dialogContext.l10n.confirm),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
try {
|
||||
return await overlay.future;
|
||||
} finally {
|
||||
controller.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> showDeleteSettingsEntryDialog(BuildContext context, String name) async {
|
||||
final overlay = const shad.DialogOverlayHandler().show<bool>(
|
||||
context: context,
|
||||
alignment: Alignment.center,
|
||||
barrierDismissable: false,
|
||||
builder: (dialogContext) => shad.AlertDialog(
|
||||
title: Text(dialogContext.l10n.confirmDeleteTitle),
|
||||
content: Text(dialogContext.l10n.confirmDeleteNamed(name)),
|
||||
actions: [
|
||||
shad.SecondaryButton(
|
||||
onPressed: () => shad.closeOverlay(dialogContext, false),
|
||||
child: Text(dialogContext.l10n.cancel),
|
||||
),
|
||||
shad.DestructiveButton(
|
||||
onPressed: () => shad.closeOverlay(dialogContext, true),
|
||||
child: Text(dialogContext.l10n.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return await overlay.future ?? false;
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../../app/application/app_appearance_controller.dart';
|
||||
import '../../../../core/utils/breakpoints.dart';
|
||||
import '../../../../shared/theme/app_design_tokens.dart';
|
||||
import '../../../../shared/theme/app_palette.dart';
|
||||
import '../../../../shared/theme/app_theme_color.dart';
|
||||
import '../../../../l10n/l10n.dart';
|
||||
|
||||
class ThemeModeSelector extends StatelessWidget {
|
||||
const ThemeModeSelector({super.key, required this.value, required this.accent, required this.onChanged});
|
||||
|
||||
final AppThemeMode value;
|
||||
final AppThemeColor accent;
|
||||
final ValueChanged<AppThemeMode> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mobile = MediaQuery.sizeOf(context).width < Breakpoints.mobile;
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final available = constraints.maxWidth.isFinite ? constraints.maxWidth : 390.0;
|
||||
final optionWidth = ((available - 16) / 3).clamp(84.0, 116.0);
|
||||
return Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 10,
|
||||
alignment: mobile ? WrapAlignment.start : WrapAlignment.end,
|
||||
children: [
|
||||
_ThemeModeOption(
|
||||
mode: AppThemeMode.system,
|
||||
label: context.l10n.themeSystem,
|
||||
icon: Icons.desktop_windows_outlined,
|
||||
width: optionWidth,
|
||||
selected: value == AppThemeMode.system,
|
||||
accent: accent,
|
||||
onPressed: onChanged,
|
||||
),
|
||||
_ThemeModeOption(
|
||||
mode: AppThemeMode.light,
|
||||
label: context.l10n.themeLight,
|
||||
icon: Icons.light_mode_outlined,
|
||||
width: optionWidth,
|
||||
selected: value == AppThemeMode.light,
|
||||
accent: accent,
|
||||
onPressed: onChanged,
|
||||
),
|
||||
_ThemeModeOption(
|
||||
mode: AppThemeMode.dark,
|
||||
label: context.l10n.themeDark,
|
||||
icon: Icons.dark_mode_outlined,
|
||||
width: optionWidth,
|
||||
selected: value == AppThemeMode.dark,
|
||||
accent: accent,
|
||||
onPressed: onChanged,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ThemeColorSelector extends StatelessWidget {
|
||||
const ThemeColorSelector({super.key, required this.value, required this.onChanged});
|
||||
|
||||
final AppThemeColor value;
|
||||
final ValueChanged<AppThemeColor> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dark = AppPalette.of(context).bg.computeLuminance() < 0.2;
|
||||
final mobile = MediaQuery.sizeOf(context).width < Breakpoints.mobile;
|
||||
final swatchSize = mobile ? 38.0 : 30.0;
|
||||
return Wrap(
|
||||
spacing: mobile ? 14 : 10,
|
||||
runSpacing: 12,
|
||||
alignment: mobile ? WrapAlignment.start : WrapAlignment.end,
|
||||
children: [
|
||||
for (final color in AppThemeColor.values)
|
||||
Semantics(
|
||||
button: true,
|
||||
selected: value == color,
|
||||
label: _colorLabel(context, color),
|
||||
child: GestureDetector(
|
||||
key: ValueKey('theme-color-${color.key}'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => onChanged(color),
|
||||
child: SizedBox.square(
|
||||
dimension: swatchSize,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: value == color
|
||||
? AppPalette.of(context).textPrimary
|
||||
: AppPalette.of(context).border.withValues(alpha: 0),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: dark ? color.dark : color.light,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: AppPalette.of(context).border),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _colorLabel(BuildContext context, AppThemeColor color) => switch (color) {
|
||||
AppThemeColor.green => context.l10n.colorGreen,
|
||||
AppThemeColor.red => context.l10n.colorRed,
|
||||
AppThemeColor.rose => context.l10n.colorRose,
|
||||
AppThemeColor.orange => context.l10n.colorOrange,
|
||||
AppThemeColor.cyan => context.l10n.colorCyan,
|
||||
AppThemeColor.blue => context.l10n.colorBlue,
|
||||
AppThemeColor.amber => context.l10n.colorAmber,
|
||||
AppThemeColor.purple => context.l10n.colorPurple,
|
||||
};
|
||||
|
||||
class _ThemeModeOption extends StatefulWidget {
|
||||
const _ThemeModeOption({
|
||||
required this.mode,
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.width,
|
||||
required this.selected,
|
||||
required this.accent,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final AppThemeMode mode;
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final double width;
|
||||
final bool selected;
|
||||
final AppThemeColor accent;
|
||||
final ValueChanged<AppThemeMode> onPressed;
|
||||
|
||||
@override
|
||||
State<_ThemeModeOption> createState() => _ThemeModeOptionState();
|
||||
}
|
||||
|
||||
class _ThemeModeOptionState extends State<_ThemeModeOption> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return Semantics(
|
||||
button: true,
|
||||
selected: widget.selected,
|
||||
label: widget.label,
|
||||
child: MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('theme-mode-${widget.mode.key}'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => widget.onPressed(widget.mode),
|
||||
child: SizedBox(
|
||||
width: widget.width,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 140),
|
||||
height: 52,
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: _hovered ? palette.cardHoverBg : palette.cardBg,
|
||||
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius + 2),
|
||||
border: Border.all(
|
||||
color: widget.selected ? palette.brand : palette.border,
|
||||
width: widget.selected ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
|
||||
child: _ThemePreview(mode: widget.mode, accent: widget.accent),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(widget.icon, size: 14, color: palette.textSecondary),
|
||||
const SizedBox(width: 5),
|
||||
Flexible(
|
||||
child: Text(
|
||||
widget.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: widget.selected ? palette.textPrimary : palette.textSecondary,
|
||||
fontSize: 12,
|
||||
fontWeight: widget.selected ? FontWeight.w700 : FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ThemePreview extends StatelessWidget {
|
||||
const _ThemePreview({required this.mode, required this.accent});
|
||||
|
||||
final AppThemeMode mode;
|
||||
final AppThemeColor accent;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return switch (mode) {
|
||||
AppThemeMode.light => _PreviewSurface(
|
||||
background: AppThemePreviewColors.lightBackground,
|
||||
side: AppThemePreviewColors.lightSide,
|
||||
line: AppThemePreviewColors.lightLine,
|
||||
accent: accent.light,
|
||||
),
|
||||
AppThemeMode.dark => _PreviewSurface(
|
||||
background: AppThemePreviewColors.darkBackground,
|
||||
side: AppThemePreviewColors.darkSide,
|
||||
line: AppThemePreviewColors.darkLine,
|
||||
accent: accent.dark,
|
||||
),
|
||||
AppThemeMode.system => Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
const ColoredBox(color: AppThemePreviewColors.lightBackground),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: 0.5,
|
||||
heightFactor: 1,
|
||||
child: const ColoredBox(color: AppThemePreviewColors.darkBackground),
|
||||
),
|
||||
),
|
||||
_PreviewSurface(
|
||||
background: AppThemePreviewColors.transparent,
|
||||
side: AppThemePreviewColors.systemSide,
|
||||
line: AppThemePreviewColors.systemLine,
|
||||
accent: accent.light,
|
||||
),
|
||||
],
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class _PreviewSurface extends StatelessWidget {
|
||||
const _PreviewSurface({required this.background, required this.side, required this.line, required this.accent});
|
||||
|
||||
final Color background;
|
||||
final Color side;
|
||||
final Color line;
|
||||
final Color accent;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ColoredBox(
|
||||
color: background,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(width: 14, child: ColoredBox(color: side)),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 8, 6, 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
height: 3,
|
||||
width: 32,
|
||||
decoration: BoxDecoration(color: line, borderRadius: BorderRadius.circular(2)),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Container(
|
||||
height: 3,
|
||||
width: 22,
|
||||
decoration: BoxDecoration(
|
||||
color: line.withValues(alpha: 0.65),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
height: 3,
|
||||
decoration: BoxDecoration(color: accent, borderRadius: BorderRadius.circular(2)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user