fromAsset static method

Future<FragmentProgram> fromAsset(
  1. String assetKey
)

Creates a fragment program from the asset with key assetKey.

The asset must be a file produced as the output of the impellerc compiler. The constructed object should then be reused via the fragmentShader method to create Shader objects that can be used by Paint.shader.

Implementation

static Future<FragmentProgram> fromAsset(String assetKey) {
  // The flutter tool converts all asset keys with spaces into URI
  // encoded paths (replacing ' ' with '%20', for example). We perform
  // the same encoding here so that users can load assets with the same
  // key they have written in the pubspec.
  final String encodedKey = Uri(path: Uri.encodeFull(assetKey)).path;
  final FragmentProgram? program = _shaderRegistry[encodedKey];
  if (program != null) {
    return Future<FragmentProgram>.value(program);
  }
  return Future<FragmentProgram>.microtask(() {
    final FragmentProgram program = FragmentProgram._fromAsset(encodedKey);
    _shaderRegistry[encodedKey] = program;
    return program;
  });
}