import 'package:web_fonts/web_fonts.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:web_fonts/fonts/web_fonts_descriptor.dart'; import 'package:web_fonts/fonts/web_fonts_variant.dart'; class SiyuanFont { static const _fontFamily = 'Siyuan'; static bool _registered = false; static register(){ if (_registered){ return; } WebFonts.register(_fontFamily, { const WebFontsVariant( fontWeight: FontWeight.w300, fontStyle: FontStyle.normal, ): WebFontsFile( 'http://liveplus-static.oss-cn-beijing.aliyuncs.com/link/dev/h5/assets/fonts/SourceHanSansCN-Regular.otf', ), const WebFontsVariant( fontWeight: FontWeight.w500, fontStyle: FontStyle.normal, ): WebFontsFile( 'http://liveplus-static.oss-cn-beijing.aliyuncs.com/link/dev/h5/assets/fonts/SourceHanSansCN-Medium.otf', ), const WebFontsVariant( fontWeight: FontWeight.w700, fontStyle: FontStyle.normal, ): WebFontsFile( 'http://liveplus-static.oss-cn-beijing.aliyuncs.com/link/dev/h5/assets/fonts/SourceHanSansCN-Heavy.otf', ), }); _registered = true; } static TextStyle getTextStyle([TextStyle? textStyle]) { register(); return WebFonts.getTextStyle(_fontFamily, textStyle: textStyle); } static TextTheme getTextTheme([TextTheme? textTheme]) { register(); return WebFonts.getTextTheme(_fontFamily, textTheme); } }