ix_theme.dart 3.3 KB

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