HelloImKevo / ComposeMultiplatformProjects

Compose Multiplatform Projects
0 stars 0 forks source link

Currency Picker AlertDialog: mutableStateList not populated with initial currency entries #3

Open HelloImKevo opened 3 months ago

HelloImKevo commented 3 months ago

The remember { mutableStateList } mechanism is not functioning correctly in the CurrencyPickerDialog.kt: https://github.com/HelloImKevo/ComposeMultiplatformProjects/commit/61d5becdd1eda16389f4d6fcb502507aff551254#diff-2f2484e88bb1f781a1d16299ff254c3f22e85f467a9d147025051d098b6ad1f4R48

When the AlertDialog is first spawned, the result set is empty, even thought 151 currency entities are provided in the Composable function / constructor.

See also: https://github.com/stevdza-san/CurrencyApp/blob/main/composeApp/src/commonMain/kotlin/presentation/component/CurrencyPickerDialog.kt#L45

Research links: https://stackoverflow.com/questions/69718059/android-jetpack-compose-mutablestatelistof-not-doing-recomposition https://stackoverflow.com/questions/67252538/jetpack-compose-update-composable-when-list-changes

HelloImKevo commented 3 months ago

This seems to fix the issue. Not sure why the remember { } mechanism is malfunctioning...

// FIXME: The mutableStateList is not being populated, so when the AlertDialog is first
//  shown, the ErrorScreen will show until the Search Filtering is triggered.
val allCurrencies = mutableStateListOf<Currency>(*currencies.toTypedArray())