app_theme.dart 6.6 KB

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