From 2fe6148afc7516898cb8c7e84e95088bdb2b5ba6 Mon Sep 17 00:00:00 2001 From: gonuit Date: Fri, 17 Nov 2023 01:10:04 +0100 Subject: [PATCH 1/3] feat: add support for sequential font fallbacks to enhance text styling flexibility --- packages/google_fonts/lib/src/google_fonts_base.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/google_fonts/lib/src/google_fonts_base.dart b/packages/google_fonts/lib/src/google_fonts_base.dart index 00d352e5..015d3399 100755 --- a/packages/google_fonts/lib/src/google_fonts_base.dart +++ b/packages/google_fonts/lib/src/google_fonts_base.dart @@ -116,9 +116,15 @@ TextStyle googleFontsTextStyle({ pendingFontFutures.add(loadingFuture); loadingFuture.then((_) => pendingFontFutures.remove(loadingFuture)); + final currentFontFamily = textStyle.fontFamily; + return textStyle.copyWith( fontFamily: familyWithVariant.toString(), - fontFamilyFallback: [fontFamily], + fontFamilyFallback: [ + fontFamily, + if (currentFontFamily != null) currentFontFamily, + ...?textStyle.fontFamilyFallback, + ], ); } From d12d1486656247beae7c1c14ba217291965618cd Mon Sep 17 00:00:00 2001 From: gonuit Date: Fri, 17 Nov 2023 01:11:41 +0100 Subject: [PATCH 2/3] test: validate correct font fallback behaviour --- .../test/generated_font_methods_test.dart | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/google_fonts/test/generated_font_methods_test.dart b/packages/google_fonts/test/generated_font_methods_test.dart index db70cb1e..9a571264 100644 --- a/packages/google_fonts/test/generated_font_methods_test.dart +++ b/packages/google_fonts/test/generated_font_methods_test.dart @@ -105,6 +105,22 @@ void main() { expect(outputTextStyle.fontFamily, equals('Lato_regular')); }); + testWidgets('Combining text styles maintains fontFamily and fallback order', + (tester) async { + const textStyle = TextStyle(); + final outputTextStyle = GoogleFonts.lato( + textStyle: GoogleFonts.notoColorEmoji( + textStyle: textStyle, + ), + ); + + expect(outputTextStyle.fontFamily, 'Lato_regular'); + expect( + outputTextStyle.fontFamilyFallback, + ['Lato', 'NotoColorEmoji_regular', 'NotoColorEmoji'], + ); + }); + /////////////////////////// // TextStyle param tests // /////////////////////////// From 44edb6d55d71697113f88150ebb73668673193d3 Mon Sep 17 00:00:00 2001 From: gonuit Date: Fri, 17 Nov 2023 01:39:39 +0100 Subject: [PATCH 3/3] docs: update changelog --- packages/google_fonts/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/google_fonts/CHANGELOG.md b/packages/google_fonts/CHANGELOG.md index cfa79220..2cb48839 100644 --- a/packages/google_fonts/CHANGELOG.md +++ b/packages/google_fonts/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.2.0 - 2023-11-17 +### Added +- Add font fallback mechanism. This update allows for more robust handling of unavailable fonts, ensuring graceful degradation to alternative fonts. + ## 6.1.0 - 2023-09-20 ### Added - Add an example where one can select any available font