ix_theme.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import 'package:flutter/material.dart';
  2. import '../../app/data/sp/ix_sp.dart';
  3. import 'theme_extensions/theme_extension.dart';
  4. import 'dark_theme_colors.dart';
  5. import 'ix_styles.dart';
  6. import 'light_theme_colors.dart';
  7. class IXTheme {
  8. static getThemeData({required bool isLight}) {
  9. return ThemeData(
  10. // main color (app bar,tabs..etc)
  11. primaryColor: isLight
  12. ? LightThemeColors.primaryColor
  13. : DarkThemeColors.primaryColor,
  14. shadowColor: isLight
  15. ? LightThemeColors.shadowColor
  16. : DarkThemeColors.shadowColor,
  17. // secondary & background color
  18. colorScheme:
  19. ColorScheme.fromSwatch(
  20. accentColor: isLight
  21. ? LightThemeColors.accentColor
  22. : DarkThemeColors.accentColor,
  23. backgroundColor: isLight
  24. ? LightThemeColors.backgroundColor
  25. : DarkThemeColors.backgroundColor,
  26. brightness: isLight ? Brightness.light : Brightness.dark,
  27. ).copyWith(
  28. secondary: isLight
  29. ? LightThemeColors.accentColor
  30. : DarkThemeColors.accentColor,
  31. ),
  32. // color contrast (if the theme is dark text should be white for example)
  33. brightness: isLight ? Brightness.light : Brightness.dark,
  34. // card widget background color
  35. cardColor: isLight
  36. ? LightThemeColors.cardColor
  37. : DarkThemeColors.cardColor,
  38. // hint text color
  39. hintColor: isLight
  40. ? LightThemeColors.hintTextColor
  41. : DarkThemeColors.hintTextColor,
  42. canvasColor: isLight
  43. ? LightThemeColors.bgDisable
  44. : DarkThemeColors.bgDisable,
  45. splashColor: isLight ? LightThemeColors.bgScrim : DarkThemeColors.bgScrim,
  46. // divider color
  47. dividerColor: isLight
  48. ? LightThemeColors.dividerColor
  49. : DarkThemeColors.dividerColor,
  50. // app background color
  51. scaffoldBackgroundColor: isLight
  52. ? LightThemeColors.scaffoldBackgroundColor
  53. : DarkThemeColors.scaffoldBackgroundColor,
  54. highlightColor: isLight
  55. ? LightThemeColors.backgroundColor
  56. : DarkThemeColors.backgroundColor,
  57. // progress bar theme
  58. progressIndicatorTheme: ProgressIndicatorThemeData(
  59. color: isLight ? LightThemeColors.strokes2 : DarkThemeColors.strokes2,
  60. ),
  61. // appBar theme
  62. appBarTheme: IXStyles.getAppBarTheme(isLightTheme: isLight),
  63. // elevated button theme
  64. elevatedButtonTheme: IXStyles.getElevatedButtonTheme(
  65. isLightTheme: isLight,
  66. ),
  67. // text theme
  68. textTheme: IXStyles.getTextTheme(isLightTheme: isLight),
  69. // chip theme
  70. chipTheme: IXStyles.getChipTheme(isLightTheme: isLight),
  71. // icon theme
  72. iconTheme: IXStyles.getIconTheme(isLightTheme: isLight),
  73. // list tile theme
  74. listTileTheme: IXStyles.getListTileThemeData(isLightTheme: isLight),
  75. // custom themes
  76. extensions: [],
  77. );
  78. }
  79. /// update app theme and save theme type to shared pref
  80. /// (so when the app is killed and up again theme will remain the same)
  81. static changeTheme() {
  82. ReactiveTheme.toggleTheme();
  83. }
  84. /// check if the theme is light or dark
  85. bool get getThemeIsLight => IXSP.getThemeIsLight();
  86. }