Watch
1
0
Fork
You've already forked Seyyed_arc
0
forked from hesabix/arc
Seyyed_arc/hesabixUI/hesabix_ui/lib/theme/tokens/extensions.dart
Babak Alizadeh 2b5c6a2498 fix(ui): densify the business settings hub
Reuse the compact theme-token pattern from the side nav so the settings catalog uses less vertical space without changing which items appear.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-06 19:40:19 +03:30

215 lines
7.2 KiB
Dart
Executable file

import 'package:flutter/material.dart';
import 'reports_catalog.dart';
import 'semantic_colors.dart';
import 'settings_hub.dart';
import 'shell_nav.dart';
import 'theme_catalog.dart';
export 'reports_catalog.dart';
export 'semantic_colors.dart';
export 'settings_hub.dart';
export 'shell_nav.dart';
export 'theme_catalog.dart';
@immutable
class AppSpacing extends ThemeExtension<AppSpacing> {
final double xs;
final double sm;
final double md;
final double lg;
final double xl;
const AppSpacing({this.xs = 4, this.sm = 8, this.md = 12, this.lg = 16, this.xl = 24});
EdgeInsets get pagePadding => EdgeInsets.all(lg);
EdgeInsets get cardPadding => EdgeInsets.all(md);
EdgeInsets get sectionGap => EdgeInsets.symmetric(vertical: md);
@override
AppSpacing copyWith({double? xs, double? sm, double? md, double? lg, double? xl}) => AppSpacing(
xs: xs ?? this.xs,
sm: sm ?? this.sm,
md: md ?? this.md,
lg: lg ?? this.lg,
xl: xl ?? this.xl,
);
@override
AppSpacing lerp(ThemeExtension<AppSpacing>? other, double t) {
if (other is! AppSpacing) return this;
double l(double a, double b) => a + (b - a) * t;
return AppSpacing(
xs: l(xs, other.xs),
sm: l(sm, other.sm),
md: l(md, other.md),
lg: l(lg, other.lg),
xl: l(xl, other.xl),
);
}
}
@immutable
class AppRadii extends ThemeExtension<AppRadii> {
final double sm;
final double md;
final double lg;
const AppRadii({this.sm = 6, this.md = 10, this.lg = 14});
BorderRadius get smBorder => BorderRadius.circular(sm);
BorderRadius get mdBorder => BorderRadius.circular(md);
BorderRadius get lgBorder => BorderRadius.circular(lg);
@override
AppRadii copyWith({double? sm, double? md, double? lg}) => AppRadii(
sm: sm ?? this.sm,
md: md ?? this.md,
lg: lg ?? this.lg,
);
@override
AppRadii lerp(ThemeExtension<AppRadii>? other, double t) {
if (other is! AppRadii) return this;
double l(double a, double b) => a + (b - a) * t;
return AppRadii(
sm: l(sm, other.sm),
md: l(md, other.md),
lg: l(lg, other.lg),
);
}
}
/// رنگ‌های ثابت shell و پس‌زمینهٔ صفحات — از seed تم مشتق می‌شوند.
@immutable
class AppShellColors extends ThemeExtension<AppShellColors> {
final Color topBarBackground;
final Color topBarForeground;
final Color dashboardBackground;
/// رنگ آیتم «بازار افزونه‌ها» در منوی کناری.
final Color sidebarMarketplace;
final Color sidebarMarketplaceFill;
/// رنگ آیتم «تنظیمات» در منوی کناری.
final Color sidebarSettings;
final Color sidebarSettingsFill;
const AppShellColors({
required this.topBarBackground,
required this.topBarForeground,
required this.dashboardBackground,
required this.sidebarMarketplace,
required this.sidebarMarketplaceFill,
required this.sidebarSettings,
required this.sidebarSettingsFill,
});
static AppShellColors fromScheme(ColorScheme scheme, {required bool isDark}) {
final topBarBg = isDark
? Color.lerp(scheme.primary, scheme.surface, 0.25)!
: scheme.primary;
final topBarFg = ThemeData.estimateBrightnessForColor(topBarBg) == Brightness.dark
? Colors.white
: scheme.onPrimary;
final marketplace = scheme.tertiary;
final settings = scheme.secondary;
Color fillOf(Color accent) => Color.alphaBlend(
accent.withValues(alpha: isDark ? 0.30 : 0.16),
scheme.surfaceContainerLow,
);
return AppShellColors(
topBarBackground: topBarBg,
topBarForeground: topBarFg,
dashboardBackground: isDark
? scheme.surface
: Color.alphaBlend(
scheme.primary.withValues(alpha: 0.035),
scheme.surfaceContainerLowest,
),
sidebarMarketplace: marketplace,
sidebarMarketplaceFill: fillOf(marketplace),
sidebarSettings: settings,
sidebarSettingsFill: fillOf(settings),
);
}
Color? sidebarFooterForeground(String? key) {
switch (key) {
case 'plugin-marketplace':
return sidebarMarketplace;
case 'settings':
return sidebarSettings;
default:
return null;
}
}
Color? sidebarFooterFill(String? key) {
switch (key) {
case 'plugin-marketplace':
return sidebarMarketplaceFill;
case 'settings':
return sidebarSettingsFill;
default:
return null;
}
}
@override
AppShellColors copyWith({
Color? topBarBackground,
Color? topBarForeground,
Color? dashboardBackground,
Color? sidebarMarketplace,
Color? sidebarMarketplaceFill,
Color? sidebarSettings,
Color? sidebarSettingsFill,
}) =>
AppShellColors(
topBarBackground: topBarBackground ?? this.topBarBackground,
topBarForeground: topBarForeground ?? this.topBarForeground,
dashboardBackground: dashboardBackground ?? this.dashboardBackground,
sidebarMarketplace: sidebarMarketplace ?? this.sidebarMarketplace,
sidebarMarketplaceFill: sidebarMarketplaceFill ?? this.sidebarMarketplaceFill,
sidebarSettings: sidebarSettings ?? this.sidebarSettings,
sidebarSettingsFill: sidebarSettingsFill ?? this.sidebarSettingsFill,
);
@override
AppShellColors lerp(ThemeExtension<AppShellColors>? other, double t) {
if (other is! AppShellColors) return this;
return AppShellColors(
topBarBackground: Color.lerp(topBarBackground, other.topBarBackground, t)!,
topBarForeground: Color.lerp(topBarForeground, other.topBarForeground, t)!,
dashboardBackground: Color.lerp(dashboardBackground, other.dashboardBackground, t)!,
sidebarMarketplace: Color.lerp(sidebarMarketplace, other.sidebarMarketplace, t)!,
sidebarMarketplaceFill: Color.lerp(sidebarMarketplaceFill, other.sidebarMarketplaceFill, t)!,
sidebarSettings: Color.lerp(sidebarSettings, other.sidebarSettings, t)!,
sidebarSettingsFill: Color.lerp(sidebarSettingsFill, other.sidebarSettingsFill, t)!,
);
}
}
extension AppThemeExtensions on BuildContext {
AppSpacing get appSpacing => Theme.of(this).extension<AppSpacing>() ?? const AppSpacing();
AppRadii get appRadii => Theme.of(this).extension<AppRadii>() ?? const AppRadii();
AppShellNavMetrics get shellNav =>
Theme.of(this).extension<AppShellNavMetrics>() ?? const AppShellNavMetrics();
AppReportsCatalogMetrics get reportsCatalog =>
Theme.of(this).extension<AppReportsCatalogMetrics>() ?? const AppReportsCatalogMetrics();
AppSettingsHubMetrics get settingsHub =>
Theme.of(this).extension<AppSettingsHubMetrics>() ?? const AppSettingsHubMetrics();
AppShellColors get shellColors =>
Theme.of(this).extension<AppShellColors>() ??
AppShellColors.fromScheme(Theme.of(this).colorScheme, isDark: Theme.of(this).brightness == Brightness.dark);
AppSemanticColors get appSemantics {
final existing = Theme.of(this).extension<AppSemanticColors>();
if (existing != null) return existing;
final scheme = Theme.of(this).colorScheme;
final isDark = Theme.of(this).brightness == Brightness.dark;
return AppSemanticColors.fromDefinition(
themeDefinitionById(kDefaultThemeId),
isDark: isDark,
scheme: scheme,
);
}
}