Note: I later reverted this change as having a default active dealer was far easier than having to implement null safety throughout my code.
How This Occurred
In the TableDataViewModel, I adjusted the type of the _activeDealerID from State<Int> to State<Int?>, making it nullable so that the value can be an Int or a null.
How This Was Problematic
This meant that some of the previous logic in my code now had to account for a potential null being fed as an argument, which I had not equipped it to handle.
How I Fixed It
By using the syntax ?: you can define a default value to be used in the event of a null value. Using this method and also another syntax method: !!, known as a ‘non-null asserted call’, which is less safe to use as it does have the potential to cause NullPointerExceptions, but if you ensure that you verify beforehand that the variable isn’t null then it remains safe to use. However I opted against using !! syntax due to a much safer option being available: ?.let {} == true. I used this as follows.
Before
val tableConfigValid by remember {
derivedStateOf {
startingChipsValid
&& bigBlindValid
&& smallBlindValid
&& playerCount >= 4
&& playerNames[activeDealerId].isNotEmpty()
}
}After
val tableConfigValid by remember {
derivedStateOf {
startingChipsValid
&& bigBlindValid
&& smallBlindValid
&& playerCount >= 4
&& activeDealerID?.let { playerID -> playerNames[playerID].isNotEmpty() } == true } }