KotlinLeaner
11/24/2022, 5:30 AMnull
. So something like this will work when you need a state, but don’t have the value at the time it’s created: mutableStateOf<String?>(null)
Thread in Slack ConversationKotlinLeaner
11/24/2022, 5:30 AMsealed class BluetoothConnectionUIState {
object Initial : BluetoothConnectionUIState()
data class ScanningDevice(val storedDevice: SnapshotStateList<BluetoothDevice>? = null) : BluetoothConnectionUIState()
}
Actually I don't want to use Initial
child in when
statement.
var uiState by mutableStateOf<BluetoothConnectionUIState>(BluetoothConnectionUIState.Initial)
private set
Use of when
statment in compose function
when (uiState) {
is BluetoothConnectionUIState.ScanningDevice -> {
BluetoothPairContent()
}
BluetoothConnectionUIState.Initial -> {}
}
In when
statement Initial
child looks very ugly. So Is there a way to solve this problem?Pablichjenkov
11/24/2022, 7:38 AMKotlinLeaner
11/24/2022, 8:01 AMPablichjenkov
11/24/2022, 8:13 AMKotlinLeaner
11/24/2022, 8:14 AMCasey Brooks
11/24/2022, 1:15 PMmutableStateOf()
.
And to this specific snippet, I wouldn’t call the Initial
state a “throwaway value”, since it communicates valuable information, both to you, the programmer, and to the end-user. Especially if it takes time to connect to the Bluetooth device, your app might be left in that Initial
state for a while, and you should display an appropriate message to the user during that time like “Attempting to connect”KotlinLeaner
11/24/2022, 1:17 PM