text_style.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'package:flowy_infra/size.dart';
  2. import 'package:flutter/material.dart';
  3. // preserved until deprecation
  4. class Fonts {
  5. static String general = "Poppins";
  6. static String monospace = "SF Mono";
  7. static String emoji = "Noto Color Emoji";
  8. }
  9. class TextStyles {
  10. // preserved until deprecation
  11. static TextStyle general({
  12. double? fontSize,
  13. FontWeight fontWeight = FontWeight.w500,
  14. Color? color,
  15. }) =>
  16. TextStyle(
  17. fontFamily: Fonts.general,
  18. fontSize: fontSize ?? FontSizes.s12,
  19. color: color,
  20. fontWeight: fontWeight,
  21. fontFamilyFallback: [Fonts.emoji],
  22. letterSpacing: (fontSize ?? FontSizes.s12) * 0.005,
  23. );
  24. static TextStyle monospace({
  25. String? fontFamily,
  26. double? fontSize,
  27. FontWeight fontWeight = FontWeight.w400,
  28. }) =>
  29. TextStyle(
  30. fontFamily: fontFamily ?? Fonts.monospace,
  31. fontSize: fontSize ?? FontSizes.s12,
  32. fontWeight: fontWeight,
  33. fontFamilyFallback: [Fonts.emoji],
  34. );
  35. static TextStyle get title => general(
  36. fontSize: FontSizes.s18,
  37. fontWeight: FontWeight.w600,
  38. );
  39. static TextStyle get subheading => general(
  40. fontSize: FontSizes.s16,
  41. fontWeight: FontWeight.w600,
  42. );
  43. static TextStyle get subtitle => general(
  44. fontSize: FontSizes.s16,
  45. fontWeight: FontWeight.w600,
  46. );
  47. static TextStyle get body1 => general(
  48. fontSize: FontSizes.s12,
  49. fontWeight: FontWeight.w500,
  50. );
  51. static TextStyle get body2 => general(
  52. fontSize: FontSizes.s12,
  53. fontWeight: FontWeight.w400,
  54. );
  55. static TextStyle get callout => general(
  56. fontSize: FontSizes.s11,
  57. fontWeight: FontWeight.w600,
  58. );
  59. static TextStyle get caption => general(
  60. fontSize: FontSizes.s11,
  61. fontWeight: FontWeight.w400,
  62. );
  63. final String font;
  64. final Color color;
  65. TextStyles({
  66. required this.font,
  67. required this.color,
  68. });
  69. TextStyle getFontStyle({
  70. String? fontFamily,
  71. double? fontSize,
  72. FontWeight? fontWeight,
  73. Color? fontColor,
  74. double? letterSpacing,
  75. double? lineHeight,
  76. }) =>
  77. TextStyle(
  78. fontFamily: fontFamily ?? font,
  79. fontSize: fontSize ?? FontSizes.s12,
  80. color: fontColor ?? color,
  81. fontWeight: fontWeight ?? FontWeight.w500,
  82. fontFamilyFallback: const ["Noto Color Emoji"],
  83. letterSpacing: (fontSize ?? FontSizes.s12) * (letterSpacing ?? 0.005),
  84. height: lineHeight,
  85. );
  86. TextTheme generateTextTheme() {
  87. return TextTheme(
  88. displayLarge: getFontStyle(
  89. fontSize: FontSizes.s32,
  90. fontWeight: FontWeight.w600,
  91. lineHeight: 42.0,
  92. ), // h2
  93. displayMedium: getFontStyle(
  94. fontSize: FontSizes.s24,
  95. fontWeight: FontWeight.w600,
  96. lineHeight: 34.0,
  97. ), // h3
  98. displaySmall: getFontStyle(
  99. fontSize: FontSizes.s20,
  100. fontWeight: FontWeight.w600,
  101. lineHeight: 28.0,
  102. ), // h4
  103. titleLarge: getFontStyle(
  104. fontSize: FontSizes.s18,
  105. fontWeight: FontWeight.w600,
  106. ), // title
  107. titleMedium: getFontStyle(
  108. fontSize: FontSizes.s16,
  109. fontWeight: FontWeight.w600,
  110. ), // heading
  111. titleSmall: getFontStyle(
  112. fontSize: FontSizes.s14,
  113. fontWeight: FontWeight.w600,
  114. ), // subheading
  115. bodyMedium: getFontStyle(), // body-regular
  116. bodySmall: getFontStyle(fontWeight: FontWeight.w400), // body-thin
  117. );
  118. }
  119. }