Skip to content

Flutter google_fonts Package FontFeature Error

Problem Statement

When using the google_fonts package (version 6.2.0 or later) in a Flutter project, you may encounter a critical build error:

bash
Error: 'FontFeature' isn't a type.
  List<FontFeature>? fontFeatures,
       ^^^^^^^^^^^
Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.
Execution failed for task ':app:compileFlutterBuildDebug'.

This error occurs because:

  • Newer versions of google_fonts (≥6.2.0) use the FontFeature class
  • Your Flutter SDK version may be too old to include this type
  • The FontFeature class resides in dart:ui, which wasn't available in older SDK versions

Common symptoms include:

  • Build failures during flutter run or flutter build
  • Failed compilation even after downgrading the package
  • flutter clean and flutter pub get don't resolve the issue

WARNING

This issue is SDK-related - changing target devices won't fix it

The optimal solution is upgrading your Flutter SDK to ensure compatibility:

bash
flutter upgrade

Then verify in your pubspec.yaml:

yaml
environment:
  sdk: '>=3.0.0 <4.0.0' # Ensure minimum SDK version is 3.0+

Why this works:

  • Newer SDK versions include dart:ui with FontFeature
  • Maintains compatibility with latest package versions
  • Provides security patches and performance improvements

2. Downgrade google_fonts Package

If upgrading Flutter isn't feasible, downgrade the package:

  1. In pubspec.yaml:
yaml
dependencies:
  google_fonts: 6.1.0 # Note: No caret (^) prefix
  1. Run:
bash
flutter clean
flutter pub get

Compatibility matrix:

Package VersionFlutter Version Requirement
≥6.2.0Latest Flutter (recommended)
6.1.0Works with older Flutter versions
5.1.0Compatible with much older SDKs

TIP

After downgrading, remove the caret (^) before the version number to prevent accidental upgrades

Additional Troubleshooting Steps

If issues persist after downgrading:

  1. Clear build caches:
bash
flutter clean
flutter pub cache repair
  1. Delete the pubspec.lock file and run:
bash
flutter pub get
  1. Verify version resolution:
bash
flutter pub deps | grep google_fonts

Conclusion

The FontFeature error occurs due to SDK-package version mismatch. The best fix is:

Final Recommendations:

  • Regularly update your Flutter SDK (flutter upgrade quarterly)
  • Monitor package changelogs when updating dependencies
  • Validate SDK constraints in pubspec.yaml for 3rd-party packages

Most users report success with either upgrading Flutter or downgrading to google_fonts: 6.1.0 without the ^ prefix.