parameter expects a lambda/function, but you are INVOKING
scaffoldStateClick()
, not passing it as a parameter. Did you mean
::scaffoldStateClick
or
scaffoldStateClick
?
(2) If you did intend to invoke
scaffoldStateClick()
and it returns a lambda, are you sure the returned lambda is of type
()->Unit
?
d
Dirk Hoffmann
02/10/2021, 5:39 PM
Copy code
fun scaffoldStateClick() = {
val adScaffoldState = ADState.ADScaffoldState
if (adScaffoldState.drawerState().isClosed) {
adScaffoldState.drawerState().open()
} else {
adScaffoldState.drawerState().close()
}
}
Dirk Hoffmann
02/10/2021, 5:40 PM
ADState.ADScaffoldState
is a singleton Object that keeps all my states and provides methods on them
(don't know if that is good design ... is it??)
j
jim
02/10/2021, 5:46 PM
You should pass your
ADScaffoldState
instance as a parameter, not use a singleton object. You always want to develop your widgets as self-contained reusable chunks that are pure functional transforms of their parameters. Relying on a global singleton violates several of those principles.
Also, your
scaffoldStateClick()
does not return a unit lambda, so that's why you're getting a type error. You probably want your code to be more like