app_theme.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import 'package:flutter/material.dart';
  2. import 'package:tdesign_flutter/tdesign_flutter.dart';
  3. import 'app_colors.dart';
  4. import 'app_colors_extension.dart';
  5. class AppTheme {
  6. AppTheme._();
  7. static Map<String, Font> _fontMap() => <String, Font>{
  8. 'fontBodyMedium': Font(size: AppFontSizes.body.toInt(), lineHeight: 22),
  9. 'fontBodySmall': Font(
  10. size: AppFontSizes.caption.toInt(),
  11. lineHeight: 20,
  12. ),
  13. 'fontTitleMedium': Font(
  14. size: AppFontSizes.subtitle.toInt(),
  15. lineHeight: 24,
  16. ),
  17. 'fontTitleLarge': Font(
  18. size: AppFontSizes.title.toInt(),
  19. lineHeight: 26,
  20. ),
  21. };
  22. /// TDesign 亮色主题
  23. static TDThemeData get tdThemeData {
  24. final base = TDThemeData.defaultData();
  25. return base.copyWithTDThemeData(
  26. 'tbossLight',
  27. colorMap: <String, Color>{
  28. 'brandNormalColor': AppColors.primary,
  29. 'brandClickColor': AppColors.primaryActive,
  30. 'successNormalColor': AppColors.success,
  31. 'warningNormalColor': AppColors.warning,
  32. 'errorNormalColor': AppColors.danger,
  33. 'textColorPrimary': AppColors.textPrimary,
  34. 'textColorSecondary': AppColors.textSecondary,
  35. 'textColorPlaceholder': AppColors.textPlaceholder,
  36. 'bgColorPage': AppColors.bgPage,
  37. 'bgColorContainer': AppColors.bgCard,
  38. 'borderColor': AppColors.border,
  39. },
  40. fontMap: _fontMap(),
  41. );
  42. }
  43. /// TDesign 深色主题
  44. static TDThemeData get darkTdThemeData {
  45. final base = TDThemeData.defaultData();
  46. return base.copyWithTDThemeData(
  47. 'tbossDark',
  48. colorMap: <String, Color>{
  49. 'brandNormalColor': AppColors.primary,
  50. 'brandClickColor': AppColors.primaryActive,
  51. 'successNormalColor': AppDarkColors.success,
  52. 'warningNormalColor': AppDarkColors.warning,
  53. 'errorNormalColor': AppDarkColors.danger,
  54. 'textColorPrimary': AppDarkColors.textPrimary,
  55. 'textColorSecondary': AppDarkColors.textSecondary,
  56. 'textColorPlaceholder': AppDarkColors.textPlaceholder,
  57. 'bgColorPage': AppDarkColors.bgPage,
  58. 'bgColorContainer': AppDarkColors.bgCard,
  59. 'borderColor': AppDarkColors.border,
  60. },
  61. fontMap: _fontMap(),
  62. );
  63. }
  64. static ThemeData get light {
  65. final colorScheme = ColorScheme.fromSeed(
  66. seedColor: AppColors.primary,
  67. brightness: Brightness.light,
  68. ).copyWith(surface: AppColors.bgPage);
  69. return ThemeData(
  70. useMaterial3: true,
  71. extensions: [AppColorsExtension.light, AppTheme.tdThemeData],
  72. colorScheme: colorScheme,
  73. canvasColor: AppColors.bgPage,
  74. scaffoldBackgroundColor: AppColors.bgPage,
  75. appBarTheme: const AppBarTheme(
  76. backgroundColor: AppColors.primary,
  77. foregroundColor: Colors.white,
  78. elevation: 0,
  79. centerTitle: false,
  80. titleTextStyle: TextStyle(
  81. fontSize: AppFontSizes.title,
  82. fontWeight: FontWeight.w600,
  83. color: Colors.white,
  84. ),
  85. ),
  86. cardTheme: CardThemeData(
  87. color: AppColors.bgCard,
  88. elevation: 1,
  89. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
  90. ),
  91. elevatedButtonTheme: ElevatedButtonThemeData(
  92. style: ElevatedButton.styleFrom(
  93. backgroundColor: AppColors.primary,
  94. foregroundColor: Colors.white,
  95. shape: RoundedRectangleBorder(
  96. borderRadius: BorderRadius.circular(22),
  97. ),
  98. minimumSize: const Size(double.infinity, 44),
  99. textStyle: const TextStyle(
  100. fontSize: AppFontSizes.body,
  101. fontWeight: FontWeight.w600,
  102. ),
  103. ),
  104. ),
  105. outlinedButtonTheme: OutlinedButtonThemeData(
  106. style: OutlinedButton.styleFrom(
  107. foregroundColor: AppColors.textPrimary,
  108. shape: RoundedRectangleBorder(
  109. borderRadius: BorderRadius.circular(22),
  110. ),
  111. minimumSize: const Size(double.infinity, 44),
  112. side: const BorderSide(color: AppColors.border),
  113. textStyle: const TextStyle(fontSize: AppFontSizes.body),
  114. ),
  115. ),
  116. dividerColor: AppColors.border,
  117. dividerTheme: const DividerThemeData(
  118. color: AppColors.border,
  119. thickness: 1,
  120. ),
  121. );
  122. }
  123. static ThemeData get dark {
  124. final colorScheme = ColorScheme.fromSeed(
  125. seedColor: AppColors.primary,
  126. brightness: Brightness.dark,
  127. ).copyWith(surface: AppDarkColors.bgPage);
  128. return ThemeData(
  129. useMaterial3: true,
  130. extensions: [AppColorsExtension.dark, AppTheme.darkTdThemeData],
  131. colorScheme: colorScheme,
  132. canvasColor: AppDarkColors.bgPage,
  133. scaffoldBackgroundColor: AppDarkColors.bgPage,
  134. appBarTheme: const AppBarTheme(
  135. backgroundColor: AppDarkColors.bgCard,
  136. foregroundColor: AppDarkColors.textPrimary,
  137. elevation: 0,
  138. centerTitle: false,
  139. titleTextStyle: TextStyle(
  140. fontSize: AppFontSizes.title,
  141. fontWeight: FontWeight.w600,
  142. color: AppDarkColors.textPrimary,
  143. ),
  144. ),
  145. cardTheme: CardThemeData(
  146. color: AppDarkColors.bgCard,
  147. elevation: 1,
  148. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
  149. ),
  150. elevatedButtonTheme: ElevatedButtonThemeData(
  151. style: ElevatedButton.styleFrom(
  152. backgroundColor: AppColors.primary,
  153. foregroundColor: Colors.white,
  154. shape: RoundedRectangleBorder(
  155. borderRadius: BorderRadius.circular(22),
  156. ),
  157. minimumSize: const Size(double.infinity, 44),
  158. textStyle: const TextStyle(
  159. fontSize: AppFontSizes.body,
  160. fontWeight: FontWeight.w600,
  161. ),
  162. ),
  163. ),
  164. outlinedButtonTheme: OutlinedButtonThemeData(
  165. style: OutlinedButton.styleFrom(
  166. foregroundColor: AppDarkColors.textPrimary,
  167. shape: RoundedRectangleBorder(
  168. borderRadius: BorderRadius.circular(22),
  169. ),
  170. minimumSize: const Size(double.infinity, 44),
  171. side: const BorderSide(color: AppDarkColors.border),
  172. textStyle: const TextStyle(fontSize: AppFontSizes.body),
  173. ),
  174. ),
  175. dividerColor: AppDarkColors.border,
  176. dividerTheme: const DividerThemeData(
  177. color: AppDarkColors.border,
  178. thickness: 1,
  179. ),
  180. );
  181. }
  182. }