2024-05-14 13:44:51 +08:00
|
|
|
import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart';
|
2024-05-03 13:41:21 +08:00
|
|
|
import 'package:appflowy_backend/log.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
|
2024-05-14 13:44:51 +08:00
|
|
|
const _defaultFontFamilies = [
|
|
|
|
defaultFontFamily,
|
|
|
|
builtInCodeFontFamily,
|
|
|
|
];
|
|
|
|
|
2024-05-03 13:41:21 +08:00
|
|
|
// if the font family is not available, google fonts packages will throw an exception
|
|
|
|
// this method will return the system font family if the font family is not available
|
|
|
|
TextStyle getGoogleFontSafely(
|
|
|
|
String fontFamily, {
|
|
|
|
FontWeight? fontWeight,
|
|
|
|
double? fontSize,
|
|
|
|
Color? fontColor,
|
|
|
|
double? letterSpacing,
|
|
|
|
double? lineHeight,
|
|
|
|
}) {
|
2024-05-14 13:44:51 +08:00
|
|
|
// if the font family is the built-in font family, we can use it directly
|
|
|
|
if (_defaultFontFamilies.contains(fontFamily)) {
|
|
|
|
return TextStyle(
|
|
|
|
fontFamily: fontFamily.isEmpty ? null : fontFamily,
|
2024-05-03 13:41:21 +08:00
|
|
|
fontWeight: fontWeight,
|
|
|
|
fontSize: fontSize,
|
|
|
|
color: fontColor,
|
|
|
|
letterSpacing: letterSpacing,
|
|
|
|
height: lineHeight,
|
|
|
|
);
|
2024-05-14 13:44:51 +08:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return GoogleFonts.getFont(
|
|
|
|
fontFamily,
|
|
|
|
fontWeight: fontWeight,
|
|
|
|
fontSize: fontSize,
|
|
|
|
color: fontColor,
|
|
|
|
letterSpacing: letterSpacing,
|
|
|
|
height: lineHeight,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
Log.error(
|
|
|
|
'Font family $fontFamily is not available, using default font family instead',
|
|
|
|
);
|
|
|
|
}
|
2024-05-03 13:41:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TextStyle(
|
|
|
|
fontWeight: fontWeight,
|
|
|
|
fontSize: fontSize,
|
|
|
|
color: fontColor,
|
|
|
|
letterSpacing: letterSpacing,
|
|
|
|
height: lineHeight,
|
|
|
|
);
|
|
|
|
}
|