loadFontsFromPackage function
Load fonts from a given package to make sure they show up in golden tests.
To use it efficiently:
- Create a flutter_test_config.dart file. See: https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html
- add
await loadFontsFromPackage(Package(name: 'my_theme', relativePath: './theme'));
in thetestExecutable
function.
Note for this function to work, your given package needs to include all fonts
it uses in a font dir at the root of the project referenced by the given package
argument.
If no package
is provided, it will look for a fonts dir at the root of the project.
If a package
is provided with a Package.relativePath it will look for a fonts dir with the package located at that path
If a package
is provided with a Package.name it will prefix the fonts dir with packages/[package.name]
Implementation
Future<void> loadFontsFromPackage({Package? package}) async {
TestWidgetsFlutterBinding.ensureInitialized();
await _load(loadFontsFromFontsDir(package));
await _loadMaterialIconFont();
}