Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 914
desmond0321 Avatar asked Oct 15 '25 03:10

desmond0321


1 Answers

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")!
like image 74
Ayan Das Avatar answered Oct 18 '25 13:10

Ayan Das



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!