Error implementing the example
Morteza-Rastgoo opened this issue · comments
Morteza Rastgoo commented
Trying to implement the example in the readme,
class MainActivity : AppCompatActivity() {
private var bottomSheet : BottomSheet? = null
private fun showActionsBottomSheet() {
bottomSheet = ActionPickerBottomSheet.init(
this,
getActionOptions().map(::ActionItem),
Config.Builder(this).build()
)
bottomSheet.setOnItemSelectedListener {
// do something...
}
bottomSheet.show()
}
fun getActionOptions() : List<Option> {
// your options
}
}
But the error appears:
Smart cast to 'ActionPickerBottomSheet' is impossible, because 'bottomSheet' is a mutable property that could have been changed by this time
Arthur Ivanets commented
Hi @Morteza-Rastgoo !
Sorry for the late response!
Yes, indeed, there was a mistake in the README; will correct it shortly.
Regarding your problem, the bottomSheet
variable is nullable, which means that in order for you to be able to operate on it you need to perform a null check first (-> bottomSheet?.show()
).