Return fonts in a deterministic order. (flutter/engine#41907)

We need to make sure to return fonts in the order we passed them in, so that unit tests don't flake if they load in a different order.
This commit is contained in:
Jackson Gardner 2023-05-10 22:13:03 -07:00 committed by GitHub
parent df4bd5d036
commit d03ba5aacb

View File

@ -69,7 +69,6 @@ class SkwasmFontCollection implements FlutterFontCollection {
@override
Future<AssetFontsResult> loadAssetFonts(FontManifest manifest) async {
final List<Future<void>> fontFutures = <Future<void>>[];
final List<String> loadedFonts = <String>[];
final Map<String, FontLoadError> fontFailures = <String, FontLoadError>{};
/// We need a default fallback font for Skwasm, in order to avoid crashing
@ -81,13 +80,13 @@ class SkwasmFontCollection implements FlutterFontCollection {
);
}
final List<String> loadedFonts = <String>[];
for (final FontFamily family in manifest.families) {
for (final FontAsset fontAsset in family.fontAssets) {
loadedFonts.add(fontAsset.asset);
fontFutures.add(() async {
final FontLoadError? error = await _downloadFontAsset(fontAsset, family.name);
if (error == null) {
loadedFonts.add(fontAsset.asset);
} else {
if (error != null) {
fontFailures[fontAsset.asset] = error;
}
}());
@ -95,6 +94,8 @@ class SkwasmFontCollection implements FlutterFontCollection {
}
await Future.wait(fontFutures);
loadedFonts.removeWhere((String assetName) => fontFailures.containsKey(assetName));
return AssetFontsResult(loadedFonts, fontFailures);
}