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

2
apps/heqi_design_system/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.dart_tool/
build/

View File

@@ -0,0 +1,45 @@
# Heqi Mobile Design System
`heqi_design_system` 是用户端与服务人员端共用的 Flutter Design System。它只负责视觉 Token、Material 3 主题和无业务状态的基础组件,不包含 API、权限、金额、状态机或领域判断。
## 使用方式
业务 App 通过本地 path dependency 引用:
```yaml
dependencies:
heqi_design_system:
path: ../heqi_design_system
```
```dart
import 'package:heqi_design_system/heqi_design_system.dart';
MaterialApp.router(
theme: HeqiTheme.light(HeqiBrand.consumer),
darkTheme: HeqiTheme.dark(HeqiBrand.consumer),
themeMode: ThemeMode.system,
);
```
## 公共 API
- `HeqiColors`:品牌色与安全语义色。
- `HeqiSpacing`4dp 间距网格。
- `HeqiRadius`:圆角层级。
- `HeqiSize`:触控区、按钮、导航和内容宽度。
- `HeqiMotion`150/220/300ms 动效节奏。
- `HeqiBreakpoints`:紧凑、中等、展开布局断点。
- `HeqiTheme`:用户端与服务端的亮色/暗色 Material 3 主题。
- `HeqiGutter``HeqiSurfaceSection``HeqiSectionHeader`:页面布局原语。
- `HeqiStatusPill``HeqiMessageState`:语义状态与空/错状态。
## 变更规则
1. 新颜色、间距、圆角或动效必须先进入 Token不得在业务页面直接写常量。
2. 安全、资金、设备命令等业务状态仍由服务端决定Design System 只负责展示映射。
3. 公共组件不得依赖任一 App 的 Domain/Data 包。
4. 破坏性 API 变更提升主版本;新增兼容 Token/组件提升次版本;视觉修复提升补丁版本。
5. 更新后必须分别执行两个 App 的 `flutter analyze``flutter test` 和构建检查。
完整设计规范见 [`docs/13-移动端Design-System.md`](../../docs/13-移动端Design-System.md)。

View File

@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml

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;
}

View File

@@ -0,0 +1,205 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
sha256: e2eb0491ba5ddb6177742d2da23904574082139b07c1e33b8503b9f46f3e1a37
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.13.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
characters:
dependency: transitive
description:
name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.1"
clock:
dependency: transitive
description:
name: clock
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.19.1"
fake_async:
dependency: transitive
description:
name: fake_async
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.3"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
url: "https://pub.flutter-io.cn"
source: hosted
version: "11.0.2"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.10"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.2"
lints:
dependency: transitive
description:
name: lints
sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.1.0"
matcher:
dependency: transitive
description:
name: matcher
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.19"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.13.0"
meta:
dependency: transitive
description:
name: meta
sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.18.0"
path:
dependency: transitive
description:
name: path
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
source_span:
dependency: transitive
description:
name: source_span
sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.12.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.4"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.2"
test_api:
dependency: transitive
description:
name: test_api
sha256: "949a932224383300f01be9221c39180316445ecb8e7547f70a41a35bf421fb9e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.11"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "0016aef94fc66495ac78af5859181e3f3bf2026bd8eecc72b9565601e19ab360"
url: "https://pub.flutter-io.cn"
source: hosted
version: "15.2.0"
sdks:
dart: ">=3.12.2 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"

View File

@@ -0,0 +1,19 @@
name: heqi_design_system
description: 和气物联网智能瓶阀移动端共享 Design System。
version: 0.1.0
publish_to: none
environment:
sdk: ^3.12.2
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_lints: ^6.0.0
flutter_test:
sdk: flutter
flutter:
uses-material-design: true

View File

@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:heqi_design_system/heqi_design_system.dart';
void main() {
test('two brands share safety semantics but use distinct primary colors', () {
final consumer = HeqiTheme.light(HeqiBrand.consumer).colorScheme;
final service = HeqiTheme.light(HeqiBrand.service).colorScheme;
expect(consumer.primary, HeqiColors.consumerPrimary);
expect(service.primary, HeqiColors.servicePrimary);
expect(consumer.error, HeqiColors.danger);
expect(service.error, HeqiColors.danger);
});
testWidgets('status pill exposes a semantic status label', (tester) async {
final semantics = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: HeqiTheme.light(HeqiBrand.consumer),
home: const Scaffold(
body: HeqiStatusPill(label: '已通过', tone: HeqiStatusTone.success),
),
),
);
expect(
find.byWidgetPredicate(
(widget) => widget is Semantics && widget.properties.label == '状态:已通过',
),
findsOneWidget,
);
semantics.dispose();
});
test('touch target follows Material mobile minimum', () {
expect(HeqiSize.minTouchTarget, greaterThanOrEqualTo(48));
});
}