desmond0321
desmond0321

Reputation: 218

Load Image from Flutter IOS plugin assets folder

I try to write a plugin for my Flutter project, I want to load an image from plugin Assets folder, do anyone know how can I load this frame.png from objective c native code?

I tried use: [[NSBundle mainBundle] pathForResource:@"frame" ofType:@"png"];

but it getting null. Anyone here know how to load this image?

Thanks

enter image description here

Upvotes: 4

Views: 1782

Answers (2)

davedega
davedega

Reputation: 11

after updating your podspec as suggested by Ayan, you can use your image like this

    ```let image = UIImage(named: "image.png",
                        in: Bundle(for: YourPlugin.self),
                        compatibleWith: nil)``` 

Upvotes: 0

Ayan Das
Ayan Das

Reputation: 278

If you are developing a flutter plugin and need to have native assets these are the following things you have to do,

  • Add your files in Assets folder or any other folder inside ios folder
  • Add the following line in podspec file

s.resources = 'Assets/*.png'

  • Access the file using Bundle
let bundle = Bundle(for: YourPlugin.self)

let url = bundle.url(forResource: "frame", withExtension: "png")!

Upvotes: 3

Related Questions