Jetpack Compose Desktop #1

Jetpack Compose Desktop #1
  • Windows
  • macOS
  • Linux/x64
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1

Get to know the code

  • main — it is the main entry point for all the code to execute
  • Window — it is used to create/open a window by holding the given content
  • remember — it remembers the value produced by calculation. calculation will only be evaluated during the composition. Re-composition will always return the value produced by composition.
  • mutableStateOf() — it returns a new MutableState initialized with the passed in value. The MutableState class is a single value holder whose reads and writes are observed by Compose. Additionally, writes to it are transacted as part of the Snapshot system.
  • MaterialTheme — it is used to define styling principles from the Material design’s specification.
  • Button() — it is a view component which is also known as a Contained Button
  • Text() — it is used to display text and thus provides accessibility to the information

Complete Code

import androidx.compose.desktop.Window
import androidx.compose.material.Text
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue

fun main() = Window {
var text by remember { mutableStateOf("Hello, World!") }

MaterialTheme {
Button(onClick = {
text = "Hello, Desktop!"
}) {
Text(text)
}
}
}
plugins {
kotlin("jvm") version "1.4.20"
id("org.jetbrains.compose") version "0.2.0-build132"
}
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1
Jetpack Compose Desktop #1

--

--

--

Android Developer | Tech Conference Speaker | Tech Writer @KotlinMumbai @NerdForTech

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Jetpack Compose Journey

⚡ Is Your Android Studio Always Slow? 🚀Here’s How to Speed Up Immediately.

Memory Management Mechanisms in Android

Android Memory leaks and Garbage collection

Scoped Storage in Android— Writing & Deleting Media Files

Android Performance — Lazy inflating Fragment with ViewStub

Pair and Triple in Kotlin

Mine Infinite is a Fun Earning App for Android

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ACE

ACE

Android Developer | Tech Conference Speaker | Tech Writer @KotlinMumbai @NerdForTech

More from Medium

Layouts in Android Jetpack Compose

Network Connectivity on Jetpack Compose

Jetpack Compose 3- Theming

How To Snap Scrollable Items To The Center Of The Screen In Jetpack Compose With Snapper

The leathery skin of a crocodile just waiting to “snap”.