I have an object of class State it contains a nullable list called playList and a nullable player object.
when I try to write this if statement
if(state.playList?.length > 0 && state.player?.currentIndex? >0)
I got this error
The operator '>' can't be unconditionally invoked because the receiver can be 'null'
I solved this issue by writing two nested if statement
if(state.playList != null && state.player?.currentIndex !=null)
{
if(state.playList!.length > 0 && state.player!.currentIndex! >0 )
{
//some code
}
}
How to rewrite the above code in better way?