style: 主题改用 Material 3 tonal 色板与标准形状体系(参考 ZL2)

This commit is contained in:
ZV Team committed 2026-10-27 20:42:07 +08:00
1 parent 6786e62263
commit 7e618adf6c
2 files changed
+195 -60

No files matched your search

+187 -44
View File
@@ -2,120 +2,263 @@ import 'package:flutter/material.dart';
enum AppThemeMode { light, dark, system } enum AppThemeMode { light, dark, system }
/// Material 3 主题(参考 ZalithLauncher 的 M3 实现风格):
/// - 用种子色生成完整 tonal palette,强调 colorScheme 的 surface container 层级
/// - 形状体系改用 M3 标准圆角(8 / 12 / 16 / 28),容器类用 16-28 的大圆角
/// - 卡片/列表靠 surfaceContainer 区分层次,弱化描边、不用阴影
class AppTheme { class AppTheme {
static const _primaryColor = Color(0xFF4CAF50); static const _primaryColor = Color(0xFF4CAF50);
/// 全局圆角体系 /// 形状体系(对齐 M3 shape scale)
static const radiusS = 10.0; // chips / 小元素 static const radiusXS = 8.0; // 小控件 / chip
static const radiusM = 14.0; // 输入框 / 按钮 static const radiusS = 12.0; // 输入框 / 按钮
static const radiusL = 18.0; // 卡片 / 弹窗 static const radiusM = 16.0; // 卡片 / 列表容器
static const radiusL = 28.0; // 弹窗 / 底部面板 / FAB
static ThemeData _base(Brightness brightness) { static ThemeData _base(Brightness brightness) {
final isDark = brightness == Brightness.dark;
final scheme = ColorScheme.fromSeed( final scheme = ColorScheme.fromSeed(
seedColor: _primaryColor, seedColor: _primaryColor,
brightness: brightness, brightness: brightness,
// 让主色更饱和、更接近 ZL2 那种"绿色主色调穿透整个界面"的效果
dynamicSchemeVariant: DynamicSchemeVariant.fidelity,
).copyWith(
surface: isDark ? const Color(0xFF101410) : const Color(0xFFF7FAF5),
surfaceContainerLowest: isDark ? const Color(0xFF0B0E0B) : Colors.white,
surfaceContainerLow: isDark ? const Color(0xFF161A16) : const Color(0xFFF1F5EE),
surfaceContainer: isDark ? const Color(0xFF1B201B) : const Color(0xFFEBF0E8),
surfaceContainerHigh: isDark ? const Color(0xFF232823) : const Color(0xFFE3E9E0),
surfaceContainerHighest: isDark ? const Color(0xFF2C322C) : const Color(0xFFDCE3D9),
); );
final isDark = brightness == Brightness.dark;
final cardColor = isDark ? scheme.surfaceContainer : scheme.surfaceContainerLowest;
final outline = isDark ? const Color(0xFF2E352E) : const Color(0xFFDDE4DA);
final shapeXS = RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusXS));
final shapeS = RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusS));
final shapeM = RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM));
final shapeL = RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusL));
return ThemeData( return ThemeData(
useMaterial3: true, useMaterial3: true,
colorScheme: scheme, colorScheme: scheme,
scaffoldBackgroundColor: isDark ? const Color(0xFF111318) : const Color(0xFFF7F8FA), scaffoldBackgroundColor: scheme.surface,
// M3 强调排版层级:标题加粗收紧字距,正文行高放宽
textTheme: Typography.material2021(platform: TargetPlatform.android)
.black
.apply(
bodyColor: scheme.onSurface,
displayColor: scheme.onSurface,
)
.copyWith(
titleLarge: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w700,
letterSpacing: -0.2,
color: scheme.onSurface,
),
titleMedium: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
letterSpacing: 0,
color: scheme.onSurface,
),
bodyMedium: TextStyle(
fontSize: 14,
height: 1.5,
color: scheme.onSurface,
),
labelLarge: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
letterSpacing: 0.1,
color: scheme.onSurface,
),
),
appBarTheme: AppBarTheme( appBarTheme: AppBarTheme(
centerTitle: true, centerTitle: false,
elevation: 0, elevation: 0,
scrolledUnderElevation: 1, scrolledUnderElevation: 0,
backgroundColor: isDark ? const Color(0xFF111318) : const Color(0xFFF7F8FA), backgroundColor: scheme.surface,
surfaceTintColor: Colors.transparent,
titleTextStyle: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w700,
letterSpacing: -0.2,
color: scheme.onSurface,
),
), ),
cardTheme: CardTheme( cardTheme: CardTheme(
elevation: 0, elevation: 0,
margin: EdgeInsets.zero, margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
color: isDark ? const Color(0xFF1B1E24) : Colors.white, color: cardColor,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radiusL), borderRadius: BorderRadius.circular(radiusM),
side: BorderSide( side: BorderSide(color: outline, width: 1),
color: isDark ? Colors.white10 : Colors.black.withOpacity(0.06),
),
), ),
), ),
inputDecorationTheme: InputDecorationTheme( inputDecorationTheme: InputDecorationTheme(
filled: true, filled: true,
fillColor: isDark ? Colors.white.withOpacity(0.05) : Colors.black.withOpacity(0.04), fillColor: isDark ? scheme.surfaceContainerHigh : scheme.surfaceContainerLow,
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12), contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(radiusM), borderRadius: BorderRadius.circular(radiusS),
borderSide: BorderSide.none, borderSide: BorderSide.none,
), ),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(radiusM), borderRadius: BorderRadius.circular(radiusS),
borderSide: BorderSide.none, borderSide: BorderSide.none,
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(radiusM), borderRadius: BorderRadius.circular(radiusS),
borderSide: BorderSide(color: scheme.primary, width: 2), borderSide: BorderSide(color: scheme.primary, width: 2),
), ),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(radiusS),
borderSide: BorderSide(color: scheme.error),
),
), ),
filledButtonTheme: FilledButtonThemeData( filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM)), shape: shapeS,
minimumSize: const Size(0, 46), minimumSize: const Size(0, 48),
textStyle: const TextStyle(fontWeight: FontWeight.w600), padding: const EdgeInsets.symmetric(horizontal: 22),
textStyle: const TextStyle(fontWeight: FontWeight.w600, fontSize: 14),
), ),
), ),
outlinedButtonTheme: OutlinedButtonThemeData( outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom( style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM)), shape: shapeS,
minimumSize: const Size(0, 46), minimumSize: const Size(0, 48),
side: BorderSide(color: scheme.outlineVariant),
textStyle: const TextStyle(fontWeight: FontWeight.w600, fontSize: 14),
), ),
), ),
textButtonTheme: TextButtonThemeData( textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom( style: TextButton.styleFrom(shape: shapeXS),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM)), ),
// M3 的 FAB 是大圆角容器(16),extended 用 16 胶囊
floatingActionButtonTheme: FloatingActionButtonThemeData(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16)),
), ),
elevation: 1,
highlightElevation: 1,
), ),
dialogTheme: DialogTheme( dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusL)), shape: shapeL,
backgroundColor: isDark ? const Color(0xFF1B1E24) : Colors.white, backgroundColor: isDark ? scheme.surfaceContainerHigh : scheme.surfaceContainerLowest,
surfaceTintColor: Colors.transparent,
),
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: isDark ? scheme.surfaceContainer : scheme.surfaceContainerLowest,
surfaceTintColor: Colors.transparent,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(28)),
),
), ),
snackBarTheme: SnackBarThemeData( snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM)), shape: shapeXS,
insetPadding: const EdgeInsets.all(16),
), ),
navigationBarTheme: NavigationBarThemeData( navigationBarTheme: NavigationBarThemeData(
height: 66, height: 72,
elevation: 0, elevation: 0,
backgroundColor: isDark ? const Color(0xFF16191F) : Colors.white, backgroundColor: isDark ? scheme.surfaceContainer : scheme.surfaceContainerLowest,
indicatorColor: scheme.primary.withOpacity(0.15), surfaceTintColor: Colors.transparent,
indicatorShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM)), indicatorColor: scheme.secondaryContainer,
indicatorShape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16)),
),
labelBehavior: NavigationDestinationLabelBehavior.alwaysShow, labelBehavior: NavigationDestinationLabelBehavior.alwaysShow,
labelTextStyle: WidgetStateProperty.resolveWith((states) {
final selected = states.contains(WidgetState.selected);
return TextStyle(
fontSize: 12,
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
color: selected ? scheme.onSurface : scheme.onSurfaceVariant,
);
}),
iconTheme: WidgetStateProperty.resolveWith((states) {
final selected = states.contains(WidgetState.selected);
return IconThemeData(
size: 24,
color: selected ? scheme.onSecondaryContainer : scheme.onSurfaceVariant,
);
}),
), ),
progressIndicatorTheme: ProgressIndicatorThemeData( progressIndicatorTheme: ProgressIndicatorThemeData(
linearTrackColor: scheme.primary.withOpacity(0.15), linearTrackColor: scheme.surfaceContainerHighest,
linearMinHeight: 8, linearMinHeight: 6,
circularTrackColor: scheme.surfaceContainerHighest,
), ),
chipTheme: ChipThemeData( chipTheme: ChipThemeData(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusS)), shape: shapeXS,
side: BorderSide.none, side: BorderSide.none,
backgroundColor: scheme.primary.withOpacity(0.08), backgroundColor: scheme.surfaceContainerHigh,
selectedColor: scheme.secondaryContainer,
labelStyle: TextStyle(fontSize: 13, color: scheme.onSurfaceVariant),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
), ),
dividerTheme: DividerThemeData( dividerTheme: DividerThemeData(
thickness: 1, thickness: 1,
space: 1, space: 1,
color: isDark ? Colors.white10 : Colors.black.withOpacity(0.06), color: scheme.outlineVariant,
), ),
listTileTheme: ListTileThemeData( listTileTheme: ListTileThemeData(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM)), shape: shapeM,
iconColor: scheme.onSurfaceVariant,
), ),
popupMenuTheme: PopupMenuThemeData( popupMenuTheme: PopupMenuThemeData(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radiusM)), shape: shapeM,
elevation: 4, elevation: 2,
color: isDark ? scheme.surfaceContainerHigh : scheme.surfaceContainerLowest,
surfaceTintColor: Colors.transparent,
), ),
expansionTileTheme: ExpansionTileThemeData( expansionTileTheme: ExpansionTileThemeData(
shape: const Border(), shape: shapeM,
collapsedShape: const Border(), collapsedShape: shapeM,
iconColor: scheme.onSurfaceVariant,
),
tabBarTheme: TabBarTheme(
dividerColor: Colors.transparent,
indicatorSize: TabBarIndicatorSize.label,
labelColor: scheme.onSurface,
unselectedLabelColor: scheme.onSurfaceVariant,
indicator: UnderlineTabIndicator(
borderSide: BorderSide(width: 3, color: scheme.primary),
borderRadius: const BorderRadius.vertical(top: Radius.circular(3)),
),
),
segmentedButtonTheme: SegmentedButtonThemeData(
style: ButtonStyle(
shape: WidgetStateProperty.all(
const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(radiusS)),
),
),
side: WidgetStateProperty.all(BorderSide(color: outline)),
textStyle: WidgetStateProperty.all(
const TextStyle(fontSize: 13, fontWeight: FontWeight.w600),
),
),
),
switchTheme: SwitchThemeData(
thumbColor: WidgetStateProperty.resolveWith((states) =>
states.contains(WidgetState.selected) ? scheme.onPrimary : scheme.outline),
trackColor: WidgetStateProperty.resolveWith((states) =>
states.contains(WidgetState.selected) ? scheme.primary : scheme.surfaceContainerHighest),
),
bottomNavigationBarTheme: BottomNavigationBarThemeData(
elevation: 0,
backgroundColor: isDark ? scheme.surfaceContainer : scheme.surfaceContainerLowest,
selectedItemColor: scheme.primary,
unselectedItemColor: scheme.onSurfaceVariant,
type: BottomNavigationBarType.fixed,
), ),
tabBarTheme: const TabBarTheme(dividerColor: Colors.transparent),
); );
} }
+8 -16
View File
@@ -261,13 +261,11 @@ class _DashboardPageState extends State<DashboardPage> {
return Card( return Card(
margin: const EdgeInsets.only(bottom: 8), margin: const EdgeInsets.only(bottom: 8),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppTheme.radiusL), borderRadius: BorderRadius.circular(AppTheme.radiusM),
side: isSel side: isSel
? BorderSide(color: Theme.of(context).colorScheme.primary, width: 1.6) ? BorderSide(color: Theme.of(context).colorScheme.primary, width: 1.6)
: BorderSide( : BorderSide(
color: Theme.of(context).brightness == Brightness.dark color: Theme.of(context).colorScheme.outlineVariant),
? Colors.white10
: Colors.black.withOpacity(0.06)),
), ),
color: isSel color: isSel
? Theme.of(context).colorScheme.primary.withOpacity(0.06) ? Theme.of(context).colorScheme.primary.withOpacity(0.06)
@@ -400,22 +398,16 @@ class _DashboardPageState extends State<DashboardPage> {
}) { }) {
return Expanded( return Expanded(
child: Material( child: Material(
color: Theme.of(context).brightness == Brightness.dark color: Theme.of(context).colorScheme.surfaceContainerLow,
? const Color(0xFF1B1E24) borderRadius: BorderRadius.circular(AppTheme.radiusM),
: Colors.white,
borderRadius: BorderRadius.circular(AppTheme.radiusL),
child: InkWell( child: InkWell(
onTap: onTap, onTap: onTap,
borderRadius: BorderRadius.circular(AppTheme.radiusL), borderRadius: BorderRadius.circular(AppTheme.radiusM),
child: Container( child: Container(
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppTheme.radiusL), borderRadius: BorderRadius.circular(AppTheme.radiusM),
border: Border.all( border: Border.all(color: Theme.of(context).colorScheme.outlineVariant),
color: Theme.of(context).brightness == Brightness.dark
? Colors.white10
: Colors.black.withOpacity(0.06),
),
), ),
child: Column( child: Column(
children: [ children: [
@@ -423,7 +415,7 @@ class _DashboardPageState extends State<DashboardPage> {
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
decoration: BoxDecoration( decoration: BoxDecoration(
color: color.withOpacity(0.14), color: color.withOpacity(0.14),
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(AppTheme.radiusS),
), ),
child: Icon(icon, color: color, size: 22), child: Icon(icon, color: color, size: 22),
), ),