theme.dart 6.6 KB

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