theme.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import 'package:flutter/material.dart';
  2. import 'color_extension.dart';
  3. Brightness themeTypeFromString(String name) {
  4. Brightness themeType = Brightness.light;
  5. if (name == "dark") {
  6. themeType = Brightness.dark;
  7. }
  8. return themeType;
  9. }
  10. String themeTypeToString(Brightness brightness) {
  11. switch (brightness) {
  12. case Brightness.light:
  13. return "light";
  14. case Brightness.dark:
  15. return "dark";
  16. }
  17. }
  18. // Color Pallettes
  19. const _black = Color(0xff000000);
  20. const _white = Color(0xFFFFFFFF);
  21. class AppTheme {
  22. Brightness brightness;
  23. late Color surface;
  24. late Color hover;
  25. late Color selector;
  26. late Color red;
  27. late Color yellow;
  28. late Color green;
  29. late Color shader1;
  30. late Color shader2;
  31. late Color shader3;
  32. late Color shader4;
  33. late Color shader5;
  34. late Color shader6;
  35. late Color shader7;
  36. late Color bg1;
  37. late Color bg2;
  38. late Color bg3;
  39. late Color bg4;
  40. late Color tint1;
  41. late Color tint2;
  42. late Color tint3;
  43. late Color tint4;
  44. late Color tint5;
  45. late Color tint6;
  46. late Color tint7;
  47. late Color tint8;
  48. late Color tint9;
  49. late Color textColor;
  50. late Color iconColor;
  51. late Color disableIconColor;
  52. late Color main1;
  53. late Color main2;
  54. late Color shadow;
  55. late String font;
  56. late String monospaceFont;
  57. /// Default constructor
  58. AppTheme({this.brightness = Brightness.light});
  59. factory AppTheme.fromName({
  60. required String themeName,
  61. required String font,
  62. required String monospaceFont,
  63. }) {
  64. switch (themeTypeFromString(themeName)) {
  65. case Brightness.light:
  66. return AppTheme(brightness: Brightness.light)
  67. ..surface = Colors.white
  68. ..hover = const Color(0xFFe0f8ff)
  69. ..selector = const Color(0xfff2fcff)
  70. ..red = const Color(0xfffb006d)
  71. ..yellow = const Color(0xffffd667)
  72. ..green = const Color(0xff66cf80)
  73. ..shader1 = const Color(0xff333333)
  74. ..shader2 = const Color(0xff4f4f4f)
  75. ..shader3 = const Color(0xff828282)
  76. ..shader4 = const Color(0xffbdbdbd)
  77. ..shader5 = const Color(0xffe0e0e0)
  78. ..shader6 = const Color(0xfff2f2f2)
  79. ..shader7 = const Color(0xffffffff)
  80. ..bg1 = const Color(0xfff7f8fc)
  81. ..bg2 = const Color(0xffedeef2)
  82. ..bg3 = const Color(0xffe2e4eb)
  83. ..bg4 = const Color(0xff2c144b)
  84. ..tint1 = const Color(0xffe8e0ff)
  85. ..tint2 = const Color(0xffffe7fd)
  86. ..tint3 = const Color(0xffffe7ee)
  87. ..tint4 = const Color(0xffffefe3)
  88. ..tint5 = const Color(0xfffff2cd)
  89. ..tint6 = const Color(0xfff5ffdc)
  90. ..tint7 = const Color(0xffddffd6)
  91. ..tint8 = const Color(0xffdefff1)
  92. ..tint9 = const Color(0xffe1fbff)
  93. ..main1 = const Color(0xff00bcf0)
  94. ..main2 = const Color(0xff00b7ea)
  95. ..textColor = _black
  96. ..iconColor = _black
  97. ..shadow = _black
  98. ..disableIconColor = const Color(0xffbdbdbd)
  99. ..font = font
  100. ..monospaceFont = monospaceFont;
  101. case Brightness.dark:
  102. return AppTheme(brightness: Brightness.dark)
  103. ..surface = const Color(0xff292929)
  104. ..hover = const Color(0xff1f1f1f)
  105. ..selector = const Color(0xff333333)
  106. ..red = const Color(0xfffb006d)
  107. ..yellow = const Color(0xffffd667)
  108. ..green = const Color(0xff66cf80)
  109. ..shader1 = _white
  110. ..shader2 = const Color(0xffffffff)
  111. ..shader3 = const Color(0xff828282)
  112. ..shader4 = const Color(0xffbdbdbd)
  113. ..shader5 = _white
  114. ..shader6 = _black
  115. ..shader7 = _black
  116. ..bg1 = _black
  117. ..bg2 = _black
  118. ..bg3 = const Color(0xff4f4f4f)
  119. ..bg4 = const Color(0xff2c144b)
  120. ..tint1 = const Color(0xffc3adff)
  121. ..tint2 = const Color(0xffffadf9)
  122. ..tint3 = const Color(0xffffadad)
  123. ..tint4 = const Color(0xffffcfad)
  124. ..tint5 = const Color(0xfffffead)
  125. ..tint6 = const Color(0xffe6ffa3)
  126. ..tint7 = const Color(0xffbcffad)
  127. ..tint8 = const Color(0xffadffe2)
  128. ..tint9 = const Color(0xffade4ff)
  129. ..main1 = const Color(0xff00bcf0)
  130. ..main2 = const Color(0xff009cc7)
  131. ..textColor = _white
  132. ..iconColor = _white
  133. ..shadow = _black
  134. ..disableIconColor = const Color(0xff333333)
  135. ..font = font
  136. ..monospaceFont = monospaceFont;
  137. }
  138. }
  139. ThemeData get themeData {
  140. return ThemeData(
  141. brightness: brightness,
  142. textTheme: TextTheme(
  143. bodyText2: TextStyle(color: shader1),
  144. ),
  145. textSelectionTheme: TextSelectionThemeData(
  146. cursorColor: main2, selectionHandleColor: main2),
  147. primaryIconTheme: IconThemeData(color: hover),
  148. iconTheme: IconThemeData(color: shader1),
  149. scrollbarTheme: ScrollbarThemeData(
  150. thumbColor: MaterialStateProperty.all(Colors.transparent),
  151. ),
  152. materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  153. canvasColor: shader6,
  154. dividerColor: shader6,
  155. hintColor: shader3,
  156. disabledColor: shader4,
  157. highlightColor: main1,
  158. indicatorColor: main1,
  159. toggleableActiveColor: main1,
  160. colorScheme: ColorScheme(
  161. brightness: brightness,
  162. primary: main1,
  163. onPrimary: shader7,
  164. primaryContainer: main2,
  165. onPrimaryContainer: shader7,
  166. secondary: hover,
  167. onSecondary: shader1,
  168. secondaryContainer: selector,
  169. onSecondaryContainer: shader1,
  170. background: surface,
  171. onBackground: shader1,
  172. surface: surface,
  173. onSurface: shader1,
  174. onError: shader7,
  175. error: red,
  176. outline: shader4,
  177. surfaceVariant: bg1,
  178. shadow: shadow,
  179. ),
  180. extensions: [
  181. CustomColors(
  182. warning: yellow,
  183. success: green,
  184. greyHover: bg2,
  185. greySelect: bg3,
  186. lightGreyHover: shader6,
  187. toggleOffFill: shader5,
  188. )
  189. ],
  190. );
  191. }
  192. Color shift(Color c, double d) =>
  193. ColorUtils.shiftHsl(c, d * (brightness == Brightness.dark ? -1 : 1));
  194. }
  195. class ColorUtils {
  196. static Color shiftHsl(Color c, [double amt = 0]) {
  197. var hslc = HSLColor.fromColor(c);
  198. return hslc.withLightness((hslc.lightness + amt).clamp(0.0, 1.0)).toColor();
  199. }
  200. static Color parseHex(String value) =>
  201. Color(int.parse(value.substring(1, 7), radix: 16) + 0xFF000000);
  202. static Color blend(Color dst, Color src, double opacity) {
  203. return Color.fromARGB(
  204. 255,
  205. (dst.red.toDouble() * (1.0 - opacity) + src.red.toDouble() * opacity)
  206. .toInt(),
  207. (dst.green.toDouble() * (1.0 - opacity) + src.green.toDouble() * opacity)
  208. .toInt(),
  209. (dst.blue.toDouble() * (1.0 - opacity) + src.blue.toDouble() * opacity)
  210. .toInt(),
  211. );
  212. }
  213. }