app_theme.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import 'package:flutter/material.dart';
  2. import 'package:tdesign_flutter/tdesign_flutter.dart';
  3. import 'app_colors.dart';
  4. class AppTheme {
  5. AppTheme._();
  6. /// TDesign 主题数据,注入自定义品牌色和字体
  7. static TDThemeData get tdThemeData {
  8. final base = TDThemeData.defaultData();
  9. return base.copyWithTDThemeData(
  10. 'tbossCustom',
  11. colorMap: <String, Color>{
  12. 'brandNormalColor': AppColors.primary,
  13. 'brandClickColor': AppColors.primaryActive,
  14. 'successNormalColor': AppColors.success,
  15. 'warningNormalColor': AppColors.warning,
  16. 'errorNormalColor': AppColors.danger,
  17. 'textColorPrimary': AppColors.textPrimary,
  18. 'textColorSecondary': AppColors.textSecondary,
  19. 'textColorPlaceholder': AppColors.textPlaceholder,
  20. 'bgColorPage': AppColors.bgPage,
  21. 'bgColorContainer': AppColors.bgCard,
  22. 'borderColor': AppColors.border,
  23. },
  24. fontMap: <String, Font>{
  25. 'fontBodyMedium': Font(size: AppFontSizes.body.toInt(), lineHeight: 22),
  26. 'fontBodySmall': Font(
  27. size: AppFontSizes.caption.toInt(),
  28. lineHeight: 20,
  29. ),
  30. 'fontTitleMedium': Font(
  31. size: AppFontSizes.subtitle.toInt(),
  32. lineHeight: 24,
  33. ),
  34. 'fontTitleLarge': Font(
  35. size: AppFontSizes.title.toInt(),
  36. lineHeight: 26,
  37. ),
  38. },
  39. );
  40. }
  41. static ThemeData get light {
  42. final colorScheme = ColorScheme.fromSeed(
  43. seedColor: AppColors.primary,
  44. brightness: Brightness.light,
  45. ).copyWith(surface: AppColors.bgPage);
  46. return ThemeData(
  47. useMaterial3: true,
  48. colorScheme: colorScheme,
  49. canvasColor: AppColors.bgPage,
  50. scaffoldBackgroundColor: AppColors.bgPage,
  51. appBarTheme: const AppBarTheme(
  52. backgroundColor: AppColors.primary,
  53. foregroundColor: Colors.white,
  54. elevation: 0,
  55. centerTitle: false,
  56. titleTextStyle: TextStyle(
  57. fontSize: AppFontSizes.title,
  58. fontWeight: FontWeight.w600,
  59. color: Colors.white,
  60. ),
  61. ),
  62. cardTheme: CardThemeData(
  63. color: AppColors.bgCard,
  64. elevation: 1,
  65. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
  66. ),
  67. elevatedButtonTheme: ElevatedButtonThemeData(
  68. style: ElevatedButton.styleFrom(
  69. backgroundColor: AppColors.primary,
  70. foregroundColor: Colors.white,
  71. shape: RoundedRectangleBorder(
  72. borderRadius: BorderRadius.circular(22),
  73. ),
  74. minimumSize: const Size(double.infinity, 44),
  75. textStyle: const TextStyle(
  76. fontSize: AppFontSizes.body,
  77. fontWeight: FontWeight.w600,
  78. ),
  79. ),
  80. ),
  81. outlinedButtonTheme: OutlinedButtonThemeData(
  82. style: OutlinedButton.styleFrom(
  83. foregroundColor: AppColors.textPrimary,
  84. shape: RoundedRectangleBorder(
  85. borderRadius: BorderRadius.circular(22),
  86. ),
  87. minimumSize: const Size(double.infinity, 44),
  88. side: const BorderSide(color: AppColors.border),
  89. textStyle: const TextStyle(fontSize: AppFontSizes.body),
  90. ),
  91. ),
  92. dividerColor: AppColors.border,
  93. dividerTheme: const DividerThemeData(
  94. color: AppColors.border,
  95. thickness: 1,
  96. ),
  97. );
  98. }
  99. }