A flutter module receiving and returning parameters between native Android and iOS

flutter_module

  • Exemplo de um módulo flutter recebendo e devolvendo parametros entre sistemas Android (Kotlin) e iOS (Swift) Nativos.

Resultado


Configurando projeto android (Kotlin)

  • Criar um módulo em flutter:
flutter create -t module --org br.com.megamil flutter_module
  • Modifique o build.gradle (app) adicione o trecho abaixo em “buildTypes”:
buildTypes {
    ...
    profile {
        initWith debug
    }
}
  • No mesmo build.gradle (app) adicione o trecho abaixo em “dependencies”
dependencies {
    ...
    debugImplementation 'br.com.megamil.flutter_module:flutter_debug:1.0'
    profileImplementation 'br.com.megamil.flutter_module:flutter_profile:1.0'
    releaseImplementation 'br.com.megamil.flutter_module:flutter_release:1.0'
}
  • Modifique o settings.gradle, adicione os maven como no exemplo abaixo, o endereço para pasta “repo” deve apostar para onde está a biblioteca exportada
dependencyResolutionManagement {
    String storageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url '../../build/host/outputs/repo'
        }
        maven {
            url "$storageUrl/download.flutter.io"
        }
    }
}
  • Para exportar para android:
flutter build aar

Preparando para chamar o fluxo

  • Adicione no AndroidManifest.xml essa activity
<activity
    android:name="io.flutter.embedding.android.FlutterActivity"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
    android:hardwareAccelerated="true"
    android:windowSoftInputMode="adjustResize" />

Configurando projeto ios (Swift)

  • Configurar Podfile Atualize o “flutter_application_path” para o caminho até a pasta “.ios” que está no flutter. No caso aqui está assim: flutter_module/.ios e o ios que vai usar o módulo está aqui dentro também, mas em outra subpasta: flutter_module/examples/ios/UsingFlutterModule por isso volto 3 níveis “../../../”
flutter_application_path = '../../../'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

Também adicione:

install_all_flutter_pods(flutter_application_path)

e o trecho

post_install do |installer|
flutter_post_install(installer) if defined?(flutter_post_install)
end

Exemplo completo:

flutter_application_path = '../../../'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target 'UsingFlutterModule' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  install_all_flutter_pods(flutter_application_path)
  # Pods for UsingFlutterModule

end

post_install do |installer|
  flutter_post_install(installer) if defined?(flutter_post_install)
end
  • Para exportar para ios:
flutter build ios-framework

GitHub

View Github

Related Posts

Recent Posts

ഇടുക്കിയിലെ മലയോര മേഖലകളിൽ രാത്രിയാത്ര നിരോധിച്ചു. രാത്രി ഏഴു മുതൽ രാവിലെ ആറു വരെയാണ് നിരോധനം

ഏന്തയാർ ഈസ്റ്റിൽ പ്രളയത്തിൽ തകർന്ന പാലത്തിന് പകരം പുതിയ പാലം നിർമ്മിക്കുവാൻ താത്ക്കാലിക പാലം പൊളിച്ച് നീക്കി

Explore the Investment Opportunities: A Comprehensive Guide to Different Types of Mutual Funds

Title: Understanding Mutual Funds: A Beginner's Guide to Investing

തീവ്രമഴ മുന്നറിയിപ്പിന്റെ പശ്ചാതലത്തിൽ സംസ്ഥാനം ജാഗ്രതയിൽ

250,000 അപേക്ഷകൾ വർദ്ധിച്ചതിനാൽ ട്രാൻസ്‌പോർട്ട് കമ്മീഷണർ പരിശോധന പുനരാരംഭിക്കും

ഏലക്കയിൽ കീടനാശിനി സാന്നിധ്യം; ആറര ലക്ഷത്തിലധികം ടിൻ അരവണ നശിപ്പിക്കാൻ ടെൻഡർ ക്ഷണിച്ച് ദേവസ്വം ബോർഡ്‌

ഭീമൻ പാറക്കഷണങ്ങൾ അടർന്ന് ദേശീയ പാതയിലേക്ക് വീഴുന്നത് പതിവാകുന്നു. കുട്ടിക്കാനത്തിനും മുണ്ടക്കയത്തിനുമിടയിൽ നിലനിൽക്കുന്നത് വൻ അപകട ഭീഷണി

ചക്രവാതച്ചുഴി:അതിശക്തമായ മഴ വരുന്നു

പ്ലസ് വൺ പ്രവേശനം. അക്ഷയയിൽ തിക്കി തിരക്കേണ്ട, നെറ്റിവിറ്റി/ജാതി തെളിയിക്കാൻ പത്താംതരം സർട്ടിഫിക്കറ്റ് മതി