Sonnat Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.6 KiB

2 years ago
  1. import 'package:data/app_setting_data/repository/app_setting_box_repository_impl.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:google_fonts/google_fonts.dart';
  4. import 'package:local_db_core/lib/boxes/box_list/setting_box/app_setting_box.dart';
  5. import 'package:repositories/app_setting_box_domain/repository/app_setting_box_repository.dart';
  6. enum FontWeights {
  7. light,
  8. regular,
  9. medium,
  10. bold,
  11. black,
  12. }
  13. enum FontFamilyName {
  14. segoeui,
  15. moshaf,
  16. moshafAEO,
  17. sname,
  18. aar,
  19. aar2,
  20. times,
  21. noor,
  22. noorAeo,
  23. }
  24. extension FontFamilyNameExtension on FontFamilyName {
  25. String get name {
  26. switch (this) {
  27. case FontFamilyName.segoeui:
  28. return 'Vazir';
  29. case FontFamilyName.moshaf:
  30. return 'Moshaf';
  31. case FontFamilyName.moshafAEO:
  32. return 'MoshafAEO';
  33. case FontFamilyName.sname:
  34. return 'sname';
  35. case FontFamilyName.aar:
  36. return 'aar';
  37. case FontFamilyName.aar2:
  38. return 'aar2';
  39. case FontFamilyName.times:
  40. return 'times';
  41. case FontFamilyName.noor:
  42. return 'noor';
  43. case FontFamilyName.noorAeo:
  44. return 'noor_aeo';
  45. }
  46. }
  47. }
  48. class AppTheme {
  49. AppTheme.privateConstructor();
  50. static final AppTheme instance = AppTheme.privateConstructor();
  51. factory AppTheme() {
  52. return instance;
  53. }
  54. final AppSettingBoxRepository _localRepository = AppSettingBoxRepositoryImpl(appSettingBox: AppSettingBox());
  55. ThemeData lightThemeData = ThemeData(
  56. brightness: Brightness.light,
  57. primaryColor: Colors.teal,
  58. checkboxTheme: const CheckboxThemeData().copyWith(),
  59. colorScheme: const ColorScheme.light().copyWith(
  60. primary: const Color(0xFF2049EB),
  61. secondary: Colors.white.withOpacity(0),
  62. ),
  63. textTheme: const TextTheme(
  64. displayLarge: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
  65. titleLarge: TextStyle(fontSize: 16.0, fontStyle: FontStyle.italic),
  66. bodyMedium: TextStyle(fontSize: 12.0),
  67. ),
  68. );
  69. final segoeFontName = 'Vazir';
  70. TextStyle fontCreator(
  71. double fontSize,
  72. FontWeights fontWeights,
  73. fontColor, [
  74. FontFamilyName? fontName,
  75. wordSpacing,
  76. lineHeight,
  77. shadow,
  78. ]) {
  79. String languageCode = _localRepository.getCurrentLanguage() ?? 'fa';
  80. if (languageCode == 'ar' &&
  81. (fontName == null || fontName == FontFamilyName.segoeui || fontName == FontFamilyName.times)) {
  82. return GoogleFonts.notoSansArabic(
  83. color: fontColor,
  84. fontStyle: FontStyle.normal,
  85. fontWeight: fontWeights == FontWeights.light
  86. ? FontWeight.w300
  87. : fontWeights == FontWeights.regular
  88. ? FontWeight.w400
  89. : fontWeights == FontWeights.medium
  90. ? FontWeight.w500
  91. : fontWeights == FontWeights.bold
  92. ? FontWeight.w700
  93. : FontWeight.w800,
  94. height: (lineHeight ?? 1) * 1.4,
  95. wordSpacing: wordSpacing,
  96. fontSize: fontSize,
  97. shadows: shadow,
  98. );
  99. }
  100. return TextStyle(
  101. color: fontColor,
  102. fontStyle: FontStyle.normal,
  103. fontFamily: fontName?.name ?? segoeFontName,
  104. fontWeight: fontWeights == FontWeights.light
  105. ? FontWeight.w300
  106. : fontWeights == FontWeights.regular
  107. ? FontWeight.w400
  108. : fontWeights == FontWeights.medium
  109. ? FontWeight.w500
  110. : fontWeights == FontWeights.bold
  111. ? FontWeight.w700
  112. : FontWeight.w800,
  113. height: lineHeight,
  114. wordSpacing: wordSpacing,
  115. fontSize: fontSize,
  116. shadows: shadow,
  117. );
  118. }
  119. }