Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

309
Visualizações
Where and How to Include File Resources Within IOS component of Flutter Plugin?

Let's say you're writing the IOS component of a Flutter plugin in Swift.

You have your MyFlutterPlugin.swift file open in XCode.

So that we know what we're talking about the same thing, it's the file that looks like this:

public class MyFlutterPlugin: NSObject, FlutterPlugin {

    public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(name: "my_flutter_plugin", binaryMessenger: registrar.messenger())
        let instance = SwiftMetronomeFlutterPlugin()
        registrar.addMethodCallDelegate(instance, channel: channel)
    }

    public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {

    // ...

    }

}

This file exists on disk at:

[your_plugin_project_name]/ios/classes/MyFlutterPlugin.swift

How could you add a resource, for example an audio (WAV) file, such that it could be referenced from within MyFlutterPlugin.swift?

In a normal (not Flutter) IOS app, I have accomplished this by simply dragging the WAV file into XCode where it sits alongside ViewController.swift (in the same folder), and referenced it from within the ViewController like this:

let clack_Path = Bundle.main.path(forResource: "clack", ofType: "wav")
let clack_URL = URL(fileURLWithPath: clack_Path!)

But, if I try that same approach from within MyFlutterPlugin.swift (putting the audio file alongside MyFlutterPlugin.swift), I get an error that clack_Path is null.

So where is the correct place to put the file, and how to properly reference it?

I can't find any code examples, tutorials, or documentation (at least not any that I recognize as being useful) on this specific problem. Hopefully it's actually possible to do on IOS... I've already got the resources included and working on the Android side of the plugin.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try this: https://docs.flutter.dev/development/ui/assets-and-images#loading-flutter-assets-in-ios

In short, firstly, put your file as a normal Flutter asset (instead of ios/android asset). Then, use the approach in the link to access it.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda