font_utils.dart 627 Bytes
import 'package:flutter/widgets.dart';

/// Provides locale-aware font selection for text widgets.
class FontUtils {
  FontUtils._();

  static const pingFangSc = 'PingFangSC';

  /// Returns PingFang SC for Chinese and English; other languages use the
  /// platform's default font.
  static String? getFontFamily(BuildContext context) {
    return getFontFamilyForLocale(Localizations.localeOf(context));
  }

  static String? getFontFamilyForLocale(Locale locale) {
    switch (locale.languageCode.toLowerCase()) {
      case 'zh':
      case 'en':
        return pingFangSc;
      default:
        return null;
    }
  }
}