theme.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'package:flowy_infra/color.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. enum ThemeType {
  5. light,
  6. dark,
  7. }
  8. class AppTheme {
  9. static ThemeType defaultTheme = ThemeType.light;
  10. bool isDark;
  11. late Color bg1; //
  12. late Color surface; //
  13. late Color bg2;
  14. late Color accent1;
  15. late Color accent1Dark;
  16. late Color accent1Darker;
  17. late Color accent2;
  18. late Color accent3;
  19. late Color grey;
  20. late Color greyStrong;
  21. late Color greyWeak;
  22. late Color error;
  23. late Color focus;
  24. late Color txt;
  25. late Color accentTxt;
  26. /// Default constructor
  27. AppTheme({this.isDark = true}) {
  28. txt = isDark ? Colors.white : Colors.black;
  29. accentTxt = isDark ? Colors.black : Colors.white;
  30. }
  31. /// fromType factory constructor
  32. factory AppTheme.fromType(ThemeType t) {
  33. switch (t) {
  34. case ThemeType.light:
  35. return AppTheme(isDark: false)
  36. ..bg1 = const Color.fromARGB(255, 247, 248, 252)
  37. ..bg2 = const Color(0xffc1dcbc)
  38. ..surface = Colors.white
  39. ..accent1 = const Color(0xff00a086)
  40. ..accent1Dark = const Color(0xff00856f)
  41. ..accent1Darker = const Color(0xff006b5a)
  42. ..accent2 = const Color(0xfff09433)
  43. ..accent3 = const Color(0xff5bc91a)
  44. ..greyWeak = const Color(0xff909f9c)
  45. ..grey = const Color(0xff515d5a)
  46. ..greyStrong = const Color(0xff151918)
  47. ..error = Colors.red.shade900
  48. ..focus = const Color(0xFF0ee2b1);
  49. case ThemeType.dark:
  50. return AppTheme(isDark: true)
  51. ..bg1 = const Color(0xff121212)
  52. ..bg2 = const Color(0xff2c2c2c)
  53. ..surface = const Color(0xff252525)
  54. ..accent1 = const Color(0xff00a086)
  55. ..accent1Dark = const Color(0xff00caa5)
  56. ..accent1Darker = const Color(0xff00caa5)
  57. ..accent2 = const Color(0xfff19e46)
  58. ..accent3 = const Color(0xff5BC91A)
  59. ..greyWeak = const Color(0xffa8b3b0)
  60. ..grey = const Color(0xffced4d3)
  61. ..greyStrong = const Color(0xffffffff)
  62. ..error = const Color(0xffe55642)
  63. ..focus = const Color(0xff0ee2b1);
  64. }
  65. }
  66. ThemeData get themeData {
  67. var t = ThemeData.from(
  68. textTheme: (isDark ? ThemeData.dark() : ThemeData.light()).textTheme,
  69. colorScheme: ColorScheme(
  70. brightness: isDark ? Brightness.dark : Brightness.light,
  71. primary: accent1,
  72. primaryVariant: accent1Darker,
  73. secondary: accent2,
  74. secondaryVariant: ColorUtils.shiftHsl(accent2, -.2),
  75. background: bg1,
  76. surface: surface,
  77. onBackground: txt,
  78. onSurface: txt,
  79. onError: txt,
  80. onPrimary: accentTxt,
  81. onSecondary: accentTxt,
  82. error: error),
  83. );
  84. return t.copyWith(
  85. materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  86. highlightColor: accent1,
  87. toggleableActiveColor: accent1);
  88. }
  89. Color shift(Color c, double d) =>
  90. ColorUtils.shiftHsl(c, d * (isDark ? -1 : 1));
  91. }