fix: font not found error log (#5449)

* fix: font not found error log

* fix: flutter analyze
This commit is contained in:
Lucas.Xu 2024-06-04 09:28:28 +08:00 committed by GitHub
parent 03e8dba5f3
commit 1e485188eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 21 deletions

View File

@ -237,8 +237,7 @@ class EditorStyleCustomizer {
try { try {
return getGoogleFontSafely(fontFamily, fontWeight: fontWeight); return getGoogleFontSafely(fontFamily, fontWeight: fontWeight);
} on Exception { } on Exception {
if ([defaultFontFamily, fallbackFontFamily, builtInCodeFontFamily] if ([defaultFontFamily, builtInCodeFontFamily].contains(fontFamily)) {
.contains(fontFamily)) {
return TextStyle(fontFamily: fontFamily, fontWeight: fontWeight); return TextStyle(fontFamily: fontFamily, fontWeight: fontWeight);
} }

View File

@ -6,7 +6,6 @@ import 'package:google_fonts/google_fonts.dart';
const _defaultFontFamilies = [ const _defaultFontFamilies = [
defaultFontFamily, defaultFontFamily,
builtInCodeFontFamily, builtInCodeFontFamily,
fallbackFontFamily,
]; ];
// if the font family is not available, google fonts packages will throw an exception // if the font family is not available, google fonts packages will throw an exception

View File

@ -41,7 +41,6 @@ class AppearanceSettingsCubit extends Cubit<AppearanceSettingsState> {
appTheme, appTheme,
appearanceSettings.themeMode, appearanceSettings.themeMode,
appearanceSettings.font, appearanceSettings.font,
appearanceSettings.monospaceFont,
appearanceSettings.layoutDirection, appearanceSettings.layoutDirection,
appearanceSettings.textDirection, appearanceSettings.textDirection,
appearanceSettings.enableRtlToolbarItems, appearanceSettings.enableRtlToolbarItems,
@ -374,7 +373,6 @@ class AppearanceSettingsState with _$AppearanceSettingsState {
required AppTheme appTheme, required AppTheme appTheme,
required ThemeMode themeMode, required ThemeMode themeMode,
required String font, required String font,
required String monospaceFont,
required LayoutDirection layoutDirection, required LayoutDirection layoutDirection,
required AppFlowyTextDirection? textDirection, required AppFlowyTextDirection? textDirection,
required bool enableRtlToolbarItems, required bool enableRtlToolbarItems,
@ -393,7 +391,6 @@ class AppearanceSettingsState with _$AppearanceSettingsState {
AppTheme appTheme, AppTheme appTheme,
ThemeModePB themeModePB, ThemeModePB themeModePB,
String font, String font,
String monospaceFont,
LayoutDirectionPB layoutDirectionPB, LayoutDirectionPB layoutDirectionPB,
TextDirectionPB? textDirectionPB, TextDirectionPB? textDirectionPB,
bool enableRtlToolbarItems, bool enableRtlToolbarItems,
@ -410,7 +407,6 @@ class AppearanceSettingsState with _$AppearanceSettingsState {
return AppearanceSettingsState( return AppearanceSettingsState(
appTheme: appTheme, appTheme: appTheme,
font: font, font: font,
monospaceFont: monospaceFont,
layoutDirection: LayoutDirection.fromLayoutDirectionPB(layoutDirectionPB), layoutDirection: LayoutDirection.fromLayoutDirectionPB(layoutDirectionPB),
textDirection: AppFlowyTextDirection.fromTextDirectionPB(textDirectionPB), textDirection: AppFlowyTextDirection.fromTextDirectionPB(textDirectionPB),
enableRtlToolbarItems: enableRtlToolbarItems, enableRtlToolbarItems: enableRtlToolbarItems,
@ -435,7 +431,7 @@ class AppearanceSettingsState with _$AppearanceSettingsState {
appTheme, appTheme,
brightness, brightness,
font, font,
monospaceFont, builtInCodeFontFamily,
); );
} }
} }

View File

@ -11,9 +11,6 @@ import 'package:flutter/material.dart';
// Desktop: Based on the OS // Desktop: Based on the OS
const defaultFontFamily = ''; const defaultFontFamily = '';
// the Poppins font is embedded in the app, so we can use it without GoogleFonts
// TODO(Lucas): after releasing version 0.5.6, remove it.
const fallbackFontFamily = 'Poppins';
const builtInCodeFontFamily = 'RobotoMono'; const builtInCodeFontFamily = 'RobotoMono';
abstract class BaseAppearance { abstract class BaseAppearance {
@ -47,7 +44,7 @@ abstract class BaseAppearance {
height: lineHeight, height: lineHeight,
); );
if (fontFamily == defaultFontFamily || fontFamily == fallbackFontFamily) { if (fontFamily == defaultFontFamily) {
return textStyle; return textStyle;
} }

View File

@ -37,7 +37,6 @@ void main() {
), ),
verify: (bloc) { verify: (bloc) {
expect(bloc.state.font, defaultFontFamily); expect(bloc.state.font, defaultFontFamily);
expect(bloc.state.monospaceFont, 'SF Mono');
expect(bloc.state.themeMode, ThemeMode.system); expect(bloc.state.themeMode, ThemeMode.system);
}, },
); );

View File

@ -1,17 +1,17 @@
import 'package:appflowy/workspace/presentation/settings/pages/settings_workspace_view.dart';
import 'package:appflowy/workspace/presentation/settings/shared/settings_radio_select.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart'; import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
import 'package:appflowy/user/application/user_settings_service.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart'; import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/presentation/settings/pages/settings_workspace_view.dart';
import 'package:appflowy/workspace/presentation/settings/shared/settings_radio_select.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_setting.pb.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_setting.pb.dart';
import 'package:appflowy/user/application/user_settings_service.dart';
import '../util.dart'; import '../util.dart';
@ -41,7 +41,6 @@ void main() {
AppTheme.fallback, AppTheme.fallback,
appearanceSettings.themeMode, appearanceSettings.themeMode,
appearanceSettings.font, appearanceSettings.font,
appearanceSettings.monospaceFont,
appearanceSettings.layoutDirection, appearanceSettings.layoutDirection,
appearanceSettings.textDirection, appearanceSettings.textDirection,
appearanceSettings.enableRtlToolbarItems, appearanceSettings.enableRtlToolbarItems,