feat(apps): establish shared mobile design system

This commit is contained in:
2026-08-10 23:31:44 +08:00
parent 7242048abf
commit a2383fc8a1
34 changed files with 2007 additions and 751 deletions

View File

@@ -0,0 +1,5 @@
library;
export 'src/components.dart';
export 'src/theme.dart';
export 'src/tokens.dart';

View File

@@ -0,0 +1,204 @@
import 'package:flutter/material.dart';
import 'tokens.dart';
enum HeqiStatusTone { neutral, info, success, warning, danger }
class HeqiGutter extends StatelessWidget {
const HeqiGutter({required this.child, super.key});
final Widget child;
@override
Widget build(BuildContext context) => Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: HeqiSize.contentMaxWidth),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal:
MediaQuery.sizeOf(context).width >= HeqiBreakpoints.compact
? HeqiSpacing.x7
: HeqiSpacing.x5,
),
child: child,
),
),
);
}
class HeqiSurfaceSection extends StatelessWidget {
const HeqiSurfaceSection({
required this.child,
this.padding = const EdgeInsets.all(HeqiSpacing.x5),
super.key,
});
final Widget child;
final EdgeInsetsGeometry padding;
@override
Widget build(BuildContext context) => DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(HeqiRadius.large),
border: Border.all(color: Theme.of(context).colorScheme.outlineVariant),
),
child: Padding(padding: padding, child: child),
);
}
class HeqiSectionHeader extends StatelessWidget {
const HeqiSectionHeader({
required this.title,
this.description,
this.trailing,
super.key,
});
final String title;
final String? description;
final Widget? trailing;
@override
Widget build(BuildContext context) => Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: Theme.of(context).textTheme.titleLarge),
if (description != null) ...[
const SizedBox(height: HeqiSpacing.x1),
Text(
description!,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
],
),
),
?trailing,
],
);
}
class HeqiStatusPill extends StatelessWidget {
const HeqiStatusPill({
required this.label,
this.tone = HeqiStatusTone.neutral,
this.icon,
super.key,
});
final String label;
final HeqiStatusTone tone;
final IconData? icon;
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final (foreground, background) = switch (tone) {
HeqiStatusTone.info => (
scheme.onPrimaryContainer,
scheme.primaryContainer,
),
HeqiStatusTone.success => (
scheme.onSecondaryContainer,
scheme.secondaryContainer,
),
HeqiStatusTone.warning => (
scheme.onTertiaryContainer,
scheme.tertiaryContainer,
),
HeqiStatusTone.danger => (scheme.onErrorContainer, scheme.errorContainer),
HeqiStatusTone.neutral => (
scheme.onSurfaceVariant,
scheme.surfaceContainerHighest,
),
};
return Semantics(
label: '状态:$label',
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: background,
borderRadius: BorderRadius.circular(HeqiRadius.small),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (icon != null) ...[
Icon(icon, size: HeqiSize.iconSmall, color: foreground),
const SizedBox(width: HeqiSpacing.x1),
],
Text(
label,
style: Theme.of(
context,
).textTheme.labelSmall?.copyWith(color: foreground),
),
],
),
),
);
}
}
class HeqiMessageState extends StatelessWidget {
const HeqiMessageState({
required this.title,
required this.description,
this.onRetry,
this.icon = Icons.info_outline_rounded,
super.key,
});
final String title;
final String description;
final VoidCallback? onRetry;
final IconData icon;
@override
Widget build(BuildContext context) => Center(
child: Padding(
padding: const EdgeInsets.all(HeqiSpacing.x8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 64,
height: 64,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
shape: BoxShape.circle,
),
child: Icon(
icon,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: HeqiSpacing.x5),
Text(
title,
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
const SizedBox(height: HeqiSpacing.x2),
Text(
description,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
if (onRetry != null) ...[
const SizedBox(height: HeqiSpacing.x5),
OutlinedButton.icon(
onPressed: onRetry,
icon: const Icon(Icons.refresh_rounded),
label: const Text('重新加载'),
),
],
],
),
),
);
}

View File

@@ -0,0 +1,209 @@
import 'package:flutter/material.dart';
import 'tokens.dart';
/// 共享 Material 3 主题。业务 App 只能选择品牌,不应复制本主题后自行修改。
abstract final class HeqiTheme {
static ThemeData light(HeqiBrand brand) => _theme(brand, Brightness.light);
static ThemeData dark(HeqiBrand brand) => _theme(brand, Brightness.dark);
static ThemeData _theme(HeqiBrand brand, Brightness brightness) {
final dark = brightness == Brightness.dark;
final seed = switch (brand) {
HeqiBrand.consumer => HeqiColors.consumerPrimary,
HeqiBrand.service => HeqiColors.servicePrimary,
};
final darkPrimary = switch (brand) {
HeqiBrand.consumer => const Color(0xFFAFC6FF),
HeqiBrand.service => const Color(0xFFC5C0FF),
};
final scheme = ColorScheme.fromSeed(
seedColor: seed,
brightness: brightness,
primary: dark ? darkPrimary : seed,
secondary: dark ? const Color(0xFF86D7B5) : HeqiColors.success,
error: dark ? const Color(0xFFFFB4AB) : HeqiColors.danger,
surface: dark ? HeqiColors.darkSurface : Colors.white,
);
final textTheme = _textTheme;
final radius = BorderRadius.circular(HeqiRadius.large);
return ThemeData(
brightness: brightness,
useMaterial3: true,
colorScheme: scheme,
scaffoldBackgroundColor: dark
? HeqiColors.darkBackground
: HeqiColors.lightBackground,
textTheme: textTheme,
visualDensity: VisualDensity.standard,
appBarTheme: AppBarTheme(
backgroundColor: Colors.transparent,
foregroundColor: scheme.onSurface,
elevation: 0,
scrolledUnderElevation: 0,
centerTitle: false,
titleTextStyle: textTheme.titleLarge?.copyWith(color: scheme.onSurface),
),
cardTheme: CardThemeData(
color: scheme.surface,
elevation: 0,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: radius,
side: BorderSide(color: scheme.outlineVariant),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: dark ? scheme.surfaceContainerHigh : scheme.surface,
contentPadding: const EdgeInsets.symmetric(
horizontal: HeqiSpacing.x4,
vertical: HeqiSpacing.x4,
),
border: OutlineInputBorder(
borderRadius: radius,
borderSide: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: radius,
borderSide: BorderSide(color: scheme.outlineVariant),
),
focusedBorder: OutlineInputBorder(
borderRadius: radius,
borderSide: BorderSide(color: scheme.primary, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: radius,
borderSide: BorderSide(color: scheme.error),
),
),
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(
minimumSize: const Size.fromHeight(HeqiSize.buttonHeight),
shape: RoundedRectangleBorder(borderRadius: radius),
textStyle: textTheme.labelLarge,
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(HeqiSize.buttonHeight),
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: radius),
textStyle: textTheme.labelLarge,
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(HeqiSize.buttonHeight),
shape: RoundedRectangleBorder(borderRadius: radius),
textStyle: textTheme.labelLarge,
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
minimumSize: const Size.square(HeqiSize.minTouchTarget),
textStyle: textTheme.labelLarge,
),
),
navigationBarTheme: NavigationBarThemeData(
height: HeqiSize.navigationBarHeight,
elevation: 0,
backgroundColor: scheme.surface,
indicatorColor: scheme.primaryContainer,
labelTextStyle: WidgetStateProperty.resolveWith(
(states) => textTheme.labelSmall?.copyWith(
color: states.contains(WidgetState.selected)
? scheme.primary
: scheme.onSurfaceVariant,
fontWeight: states.contains(WidgetState.selected)
? FontWeight.w700
: FontWeight.w500,
),
),
),
chipTheme: ChipThemeData(
side: BorderSide.none,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(HeqiRadius.small),
),
labelStyle: textTheme.labelSmall,
),
listTileTheme: const ListTileThemeData(
minTileHeight: 56,
contentPadding: EdgeInsets.symmetric(
horizontal: HeqiSpacing.x4,
vertical: HeqiSpacing.x1,
),
),
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: scheme.surface,
modalBackgroundColor: scheme.surface,
showDragHandle: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(HeqiRadius.sheet),
),
),
),
dialogTheme: DialogThemeData(
backgroundColor: scheme.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(HeqiRadius.sheet),
),
),
dividerTheme: DividerThemeData(
color: scheme.outlineVariant,
thickness: 1,
space: 1,
),
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(HeqiRadius.medium),
),
),
);
}
static const _textTheme = TextTheme(
displaySmall: TextStyle(
fontSize: 32,
height: 1.25,
fontWeight: FontWeight.w700,
),
headlineMedium: TextStyle(
fontSize: 28,
height: 1.28,
fontWeight: FontWeight.w700,
),
headlineSmall: TextStyle(
fontSize: 24,
height: 1.33,
fontWeight: FontWeight.w700,
),
titleLarge: TextStyle(
fontSize: 22,
height: 1.27,
fontWeight: FontWeight.w600,
),
titleMedium: TextStyle(
fontSize: 16,
height: 1.5,
fontWeight: FontWeight.w600,
),
bodyLarge: TextStyle(fontSize: 16, height: 1.5),
bodyMedium: TextStyle(fontSize: 14, height: 1.55),
labelLarge: TextStyle(
fontSize: 14,
height: 1.4,
fontWeight: FontWeight.w600,
),
labelSmall: TextStyle(
fontSize: 12,
height: 1.35,
fontWeight: FontWeight.w500,
),
);
}

View File

@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
/// 两端品牌主题。安全语义色始终共享,不能被品牌色覆盖。
enum HeqiBrand { consumer, service }
abstract final class HeqiColors {
static const consumerPrimary = Color(0xFF2563EB);
static const servicePrimary = Color(0xFF4F46E5);
static const success = Color(0xFF16875D);
static const warning = Color(0xFFB86400);
static const danger = Color(0xFFC7352A);
static const lightBackground = Color(0xFFF7F8FA);
static const darkBackground = Color(0xFF0B1220);
static const darkSurface = Color(0xFF111827);
}
/// 4dp 基础网格。页面不得新增不属于本表的随意间距。
abstract final class HeqiSpacing {
static const x1 = 4.0;
static const x2 = 8.0;
static const x3 = 12.0;
static const x4 = 16.0;
static const x5 = 20.0;
static const x6 = 24.0;
static const x7 = 28.0;
static const x8 = 32.0;
static const x10 = 40.0;
static const x12 = 48.0;
}
abstract final class HeqiRadius {
static const small = 10.0;
static const medium = 12.0;
static const large = 16.0;
static const extraLarge = 20.0;
static const sheet = 24.0;
}
abstract final class HeqiSize {
static const minTouchTarget = 48.0;
static const buttonHeight = 52.0;
static const navigationBarHeight = 72.0;
static const contentMaxWidth = 720.0;
static const iconSmall = 16.0;
static const iconMedium = 24.0;
static const iconLarge = 32.0;
}
abstract final class HeqiMotion {
static const fast = Duration(milliseconds: 150);
static const standard = Duration(milliseconds: 220);
static const emphasized = Duration(milliseconds: 300);
}
abstract final class HeqiBreakpoints {
static const compact = 600.0;
static const medium = 840.0;
static const expanded = 1024.0;
}