custom_font.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'package:web_fonts/web_fonts.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:web_fonts/fonts/web_fonts_descriptor.dart';
  5. import 'package:web_fonts/fonts/web_fonts_variant.dart';
  6. class SiyuanFont {
  7. static const _fontFamily = 'Siyuan';
  8. static bool _registered = false;
  9. static register(){
  10. if (_registered){
  11. return;
  12. }
  13. WebFonts.register(_fontFamily, {
  14. const WebFontsVariant(
  15. fontWeight: FontWeight.w300,
  16. fontStyle: FontStyle.normal,
  17. ): WebFontsFile(
  18. 'http://liveplus-static.oss-cn-beijing.aliyuncs.com/link/dev/h5/assets/fonts/SourceHanSansCN-Regular.otf',
  19. ),
  20. const WebFontsVariant(
  21. fontWeight: FontWeight.w500,
  22. fontStyle: FontStyle.normal,
  23. ): WebFontsFile(
  24. 'http://liveplus-static.oss-cn-beijing.aliyuncs.com/link/dev/h5/assets/fonts/SourceHanSansCN-Medium.otf',
  25. ),
  26. const WebFontsVariant(
  27. fontWeight: FontWeight.w700,
  28. fontStyle: FontStyle.normal,
  29. ): WebFontsFile(
  30. 'http://liveplus-static.oss-cn-beijing.aliyuncs.com/link/dev/h5/assets/fonts/SourceHanSansCN-Heavy.otf',
  31. ),
  32. });
  33. _registered = true;
  34. }
  35. static TextStyle getTextStyle([TextStyle? textStyle]) {
  36. register();
  37. return WebFonts.getTextStyle(_fontFamily, textStyle: textStyle);
  38. }
  39. static TextTheme getTextTheme([TextTheme? textTheme]) {
  40. register();
  41. return WebFonts.getTextTheme(_fontFamily, textTheme);
  42. }
  43. }