Include Compose Multiplatform File Picker in your project
masterAdd the following dependency to your Kotlin Multiplatform project to use the file picker widgets in your shared Compose code:
implementation("com.darkrockstudios:mpfilepicker:3.1.0")repository·master·Indexed 18 days ago
https://github.com/wavesonics/compose-multiplatform-file-pickerA multiplatform Compose widget library providing access to native file picker dialogs for Windows, Android, Desktop/JVM, JS, and iOS. Includes components for picking single files, multiple files with extension filters, and directory selection.
Add the following dependency to your Kotlin Multiplatform project to use the file picker widgets in your shared Compose code:
implementation("com.darkrockstudios:mpfilepicker:3.1.0")Use the FilePicker composable to open a native file dialog. You can restrict the files shown by providing a list of extensions to the fileExtensions parameter. To trigger the dialog, set the show boolean state to true.
Note: The callback provides a platformFile object which you can use to perform actions with the selected file.
var showFilePicker by remember { mutableStateOf(false) }
val fileType = listOf("jpg", "png")
FilePicker(show = showFilePicker, fileExtensions = fileType) { platformFile ->
showFilePicker = false
// do something with the file
}Use the DirectoryPicker composable to allow users to select an entire folder/directory. The callback provides the path of the selected directory.
var showDirPicker by remember { mutableStateOf(false) }
DirectoryPicker(showDirPicker) { path ->
showDirPicker = false
// do something with path
}Use the MultipleFilePicker composable to allow users to select more than one file. Similar to FilePicker, you can use fileExtensions to filter results. The callback provides a file object (representing the selection) for each picked file.
var showFilePicker by remember { mutableStateOf(false) }
val fileType = listOf("jpg", "png")
MultipleFilePicker(show = showFilePicker, fileExtensions = fileType) { file ->
showFilePicker = false
// do something with the file
}