import 'package:flutter/material.dart'; import 'app_dims.g.dart'; import 'app_tokens.g.dart'; ThemeData buildTheme(String key) { final t = appTokensOf(key); final brightness = t.isDark ? Brightness.dark : Brightness.light; final scheme = ColorScheme.fromSeed( seedColor: t.primary, brightness: brightness, ).copyWith( primary: t.primary, onPrimary: t.onPrimary, surface: t.surface, error: t.danger, ); return ThemeData( useMaterial3: true, brightness: brightness, colorScheme: scheme, scaffoldBackgroundColor: t.bg, // 桌面端默认 adaptivePlatformDensity=compact 会把输入框/按钮压矮 8px, // 与原型 px 规格(.input h38 等)和 golden(测试环境=standard)不一致—— // 真机曾因此输入框只有 ~30 高。锁 standard,三端渲染与原型同几何。 visualDensity: VisualDensity.standard, // ── 对话框/输入框/按钮的 Material 默认样式钉到 ds 真相源 ── // 原型 .modal:surface / border / r-xl / 标题 fs-h2 heading dialogTheme: DialogThemeData( backgroundColor: t.surface, surfaceTintColor: Colors.transparent, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppDims.rXl), side: BorderSide(color: t.border), ), titleTextStyle: TextStyle( fontSize: AppDims.fsH2, fontWeight: FontWeight.w700, color: t.heading), contentTextStyle: TextStyle(fontSize: AppDims.fsBody, color: t.text), ), // 原型 .input:h38 盒式(surface/1px border/r-md/pad 0 11),聚焦主色边。 // 全局兜底——未显式给 decoration 边框的 TextField/DropdownButtonFormField // 一律盒式,禁止 Material 默认下划线再出现。 inputDecorationTheme: InputDecorationTheme( isDense: true, filled: true, fillColor: t.surface, hintStyle: TextStyle(fontSize: AppDims.fsBody, color: t.faint), labelStyle: TextStyle(fontSize: AppDims.fsSm, color: t.muted), contentPadding: const EdgeInsets.symmetric(horizontal: 11, vertical: 9), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(AppDims.rMd), borderSide: BorderSide(color: t.border), ), disabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(AppDims.rMd), borderSide: BorderSide(color: t.border), ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(AppDims.rMd), borderSide: BorderSide(color: t.primary), ), border: OutlineInputBorder( borderRadius: BorderRadius.circular(AppDims.rMd), borderSide: BorderSide(color: t.border), ), ), // 原型 .btn.primary:primary 底 / onPrimary 字 / h38 / r-md / w600 / 无阴影 elevatedButtonTheme: ElevatedButtonThemeData( style: ElevatedButton.styleFrom( backgroundColor: t.primary, foregroundColor: t.onPrimary, elevation: 0, minimumSize: const Size(0, 38), padding: const EdgeInsets.symmetric(horizontal: 16), textStyle: const TextStyle( fontSize: AppDims.fsBody, fontWeight: FontWeight.w600), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppDims.rMd)), ), ), filledButtonTheme: FilledButtonThemeData( style: FilledButton.styleFrom( backgroundColor: t.primary, foregroundColor: t.onPrimary, minimumSize: const Size(0, 38), padding: const EdgeInsets.symmetric(horizontal: 16), textStyle: const TextStyle( fontSize: AppDims.fsBody, fontWeight: FontWeight.w600), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppDims.rMd)), ), ), // TextButton 兼作行内链接,不加边框;只统一字号字重与圆角 textButtonTheme: TextButtonThemeData( style: TextButton.styleFrom( minimumSize: const Size(0, 38), textStyle: const TextStyle( fontSize: AppDims.fsBody, fontWeight: FontWeight.w600), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppDims.rMd)), ), ), // 字体走系统默认(macOS/iOS=PingFang SC,与原型 --font 一致);不强制 Noto。 // Noto 仅 golden 测试加载(CI 无中文字体),见 test/support/golden_harness.dart。 extensions: >[t], ); }