waitForPendingDecodes method

  1. @visibleForTesting
Future<void> waitForPendingDecodes()

A future that completes when any in-flight vector graphic decodes have completed.

A vector graphic may require asynchronous work during decoding, for example to decode an image that was embedded in the source graphic. This method may be useful in golden image unit tests.

await tester.pumpWidget(MyWidgetThatHasVectorGraphics());
await tester.runAsync(() => vg.waitForPendingDecodes());
await expect(
  find.byType(MyWidgetThatHasVectorGraphics),
  matchesGoldenFile('golden_file.png'),
);

Without the waitForPendingDecodes call, the golden file would have the placeholder for the VectorGraphic widgets, which defaults to a blank sized box.

Implementation

@visibleForTesting
Future<void> waitForPendingDecodes() {
  if (kDebugMode) {
    // ignore: invalid_use_of_visible_for_testing_member
    return Future.wait(debugGetPendingDecodeTasks);
  }
  throw UnsupportedError(
    'This method is only for use in tests in debug mode for tests.',
  );
}