From the course: Kotlin Multiplatform Development

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Accessing operating system methods

Accessing operating system methods - Kotlin Tutorial

From the course: Kotlin Multiplatform Development

Accessing operating system methods

- [Instructor] In this video, we're going to call methods or functions that are specific for each operating system, but we're going to make that call from shared code. You see here, I have created a platform function with expect fun, and I gave it the composable annotation. This makes it a Compose Multiplatform function, so then we can actually make this call from Compose code and also take advantage of some of the Compose methods. So we're going to use this expect fun to create a function interface that we satisfy with a different Kotlin function for each platform, so let's take a look at Android here. Starting with Android, we create a sequence of toasts, so toast is a system message that briefly appears over the top of our app, covering everything underneath it. In this case, we define our platform func to show two different messages with the Toast.makeText method, which only Android supports, passing in the Android context that we get from the composable, so LocalContext.current…

Contents