Hi. I want to trigger a file select dialog from compose multiplatform. How can it be done?
So I have a small code like this
fun main() {
onWasmReady {
Window {
var selectedDestination by remember { mutableStateOf(Destinations.HISTORY) }
val destinations = Destinations.values()
Row {
NavigationRail {
FloatingActionButton(onClick = {
// TODO show file dialog here
}, shape = RoundedCornerShape(10.dp)) {
Icon(Icons.Filled.Add, contentDescription = "Add")
}
Spacer(Modifier.height(16.dp))
destinations.forEach { item ->
NavigationRailItem(
icon = { Icon(item.icon, contentDescription = item.title) },
label = { Text(item.title) },
selected = selectedDestination == item,
onClick = { selectedDestination = item }
)
}
}
when (selectedDestination) {
Destinations.HISTORY -> HistoryPage()
Destinations.STATS -> StatsPage()
Destinations.DOWNLOADS -> DownloadsPage()
Destinations.SETTINGS -> SettingsPage()
}
}
}
}
}
and when user clicks the
FloatingActionButton
he should be able to select a file. I tried to do it like here
https://stackoverflow.com/a/8385882/4885394 but im not able to translate Javascript to Kotlin. How can I create an Input element and then add a click listener? tried like
document.createElement("input")
but then it has different type and I dont know to what I should cast it.
Before I had this
Input(InputType.File) {
onChange {
val file = it.target.files?.asList()?.first()
if (file != null) {
scope.launch {
output = try {
YoutubeHistory(file.text(), minVideoClicks).toString()
} catch (e: Exception) {
e.message ?: "Unknown Error"
}
}
}
}
}
and it worked. Thats what I want to achieve but in actual multiplatform compose. Or what do you guys call it? the version that uses skia on web with canvas