210 lines
6.7 KiB
Dart
210 lines
6.7 KiB
Dart
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,
|
|
),
|
|
);
|
|
}
|