Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/voize-gmbh/flutter-kmp
Combine Flutter with Kotlin Multiplatform (KMP)
https://github.com/voize-gmbh/flutter-kmp
flutter kmp kotlin kotlin-multiplatform
Last synced: 3 months ago
JSON representation
Combine Flutter with Kotlin Multiplatform (KMP)
- Host: GitHub
- URL: https://github.com/voize-gmbh/flutter-kmp
- Owner: voize-gmbh
- Created: 2024-05-24T21:54:49.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-07-28T00:08:14.000Z (6 months ago)
- Last Synced: 2024-07-28T23:52:57.487Z (6 months ago)
- Topics: flutter, kmp, kotlin, kotlin-multiplatform
- Language: Kotlin
- Homepage:
- Size: 141 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# flutter-kmp
## Installation
Add the KSP gradle plugin to your multiplatform project's build.gradle.kts file, if you have subprojects, add it to the subproject's build.gradle.kts file.
```kotlin
// android/shared/build.gradle.ktsplugins {
// from gradlePluginPortal()
id("com.google.devtools.ksp") version "1.9.23-1.0.20"
}
```Then add the `flutter-kmp` to the commonMain source set dependencies. Also add the generated common source set to the commonMain source set:
```kotlin
// android/shared/build.gradle.ktsval commonMain by getting {
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
dependencies {
// ...
implementation("de.voize:flutter-kmp:")
}
}
```Add `flutter-kmp-stubs` as `compileOnly` dependency to the androidMain source set:
```kotlin
// android/shared/build.gradle.ktsval androidMain by getting {
dependencies {
// ...
compileOnly("de.voize:flutter-kmp-stubs:")
}
}
```Then add `flutter-kmp-ksp` to the KSP configurations:
```kotlin
// android/shared/build.gradle.ktsdependencies {
add("kspCommonMainMetadata", "de.voize:flutter-kmp-ksp:")
add("kspAndroid", "de.voize:flutter-kmp-ksp:")
add("kspIosX64", "de.voize:flutter-kmp-ksp:")
add("kspIosArm64", "de.voize:flutter-kmp-ksp:")
// (if needed) add("kspIosSimulatorArm64", "de.voize:flutter-kmp-ksp:")
}
```Configure the KSP task dependencies and copy the generated Dart files to your flutter plugin:
```kotlin
// android/shared/build.gradle.ktstasks.withType>().configureEach {
if(name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
} else {
finalizedBy("copyGeneratedDartFiles")
}
}tasks.register("copyGeneratedDartFiles") {
dependsOn("kspCommonMainKotlinMetadata")
from("build/generated/ksp/metadata/commonMain/resources/flutterkmp")
into("path/to/flutter/lib/generated")
}
```Register the generated Android module classes (ending with `...Android.kt`) in your Flutter plugin Android class:
```kotlin
class MyFlutterPlugin: FlutterPlugin {
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
MyFlutterModuleAndroid()
// ...
}...
}
```The generated Dart code uses the `json_serializable` package.
Add the following dependencies to your Flutter plugin:```
flutter pub add json_annotation dev:build_runner dev:json_serializable
```Then after generating Dart data classes make sure to the following command to generate the serialization code:
```
dart run build_runner build --delete-conflicting-outputs
```