skip to Main Content

I’m trying to write some custom graphics stuff, but got stuck at loading shaders.

I have this:

void loadMyShader() async {
   var program = await FragmentProgram.fromAsset('shaders/myshader.frag');
}

from the webpage: https://docs.flutter.dev/development/ui/advanced/shaders

in VSCode, but I get an undefined method error for .fromAsset()

The above function definition is inside a simple class.
The only method that gets suggested is .compile(), but that expects some spirv code I don’t know.
Is it an issue with the api being beta, or something completely obvious I’m missing here?

I haven’t compiled the code, I just see the error message described above.

2

Answers


  1. Chosen as BEST ANSWER

    I needed to upgrade flutter. 3.7.7 has it


  2. In your pubspec.yaml change the location of where you list your shaders from assets: to shaders:. your final yaml should look like this:

      assets:
        - assets/fonts/
        - assets/icons/
        - assets/images/
    
      shaders:
        - assets/shaders/simple.frag
        - assets/shaders/toon_cloud.frag
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search