I have the following ViewModel
@HiltViewModel class ShareViewModel @Inject constructor( private val taskRepository: TaskRepository ): ViewModel() { private val searchAppBarStateMutableState: MutableState<SearchAppBarState> = mutableStateOf(SearchAppBarState.CLOSED) val searchAppBarState: State<SearchAppBarState> = searchAppBarStateMutableState private val listOfTaskMutableStateFlow = MutableStateFlow<List<TodoTaskEntity>>(emptyList()) val listOfTaskStateFlow = listOfTaskMutableStateFlow.asStateFlow() } I never expose mutableStateFlow as in the example above. And SonarLint will show a warning when doing this.
MutableStateFlow" and "MutableSharedFlow" should not be exposed So I apply the same technique to the mutableState
However, If I do like this below, I don't get any warning.
val searchAppBarStateMutableState: MutableState<SearchAppBarState> = mutableStateOf(SearchAppBarState.CLOSED) Just wondering what is the best practice for using MutableState with jetpack compose.
: State<SearchAppBarState>is also a possible variant if you need to pass a state for some reason. Not sure why your linter is not happy, the flow variant seems fine too.