Questions tagged [mutablestateof]

The tag has no usage guidance.

mutablestateof
Filter by
Sorted by
Tagged with
11 votes
2 answers
3k views

Why does mutableStateOf without remember work sometimes?

I've been playing with Jetpack Compose Desktop. I noticed something I really don't understand: import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.material.Button import ...
BierDav's user avatar
  • 1,344
8 votes
1 answer
5k views

Jetpack Compose TextField not updating when typing a new character

I followed this document from the developer site. I want to display the text in an OutlinedTextField from a user input, and have it survive configuration changes. With the code below, when the user ...
Zappy.Mans's user avatar
6 votes
1 answer
4k views

How to use null as default value - Compose mutableState

I have a need like on first time on UI load the mutableStateOf Boolean value must be null , instead of default value as true/false similar to regular boolean value in Kotlin as var isBooleanValue: ...
arun's user avatar
  • 175
3 votes
0 answers
494 views

Checkbox in Jetpack compose not updating with the state value

I am creating a list of data to be multi selected and also want to add functionality by adding "Select All" option to select/deselect all the items at once. The issue I am facing is when ...
Chintak Patel's user avatar
2 votes
2 answers
676 views

mutableStateOf holding the value after the recomposition without remember API in Jetpack Compose

Any time a state is updated a recomposition takes place. but here, I haven't used the remember API, but after the recomposition also it's holding the value, is the mutableStateOf() will remember the ...
FGH's user avatar
  • 3,618
2 votes
1 answer
444 views

How SnapshotStateList detects that a change has occurred?

Suppose I have a SnapshotStateList for Student, and the definition of Student is: data class Student<val id: Int, var name: String> val students = mutableStateListOf(Student(0, "Aaron"...
progquester's user avatar
  • 1,430
2 votes
1 answer
3k views

Can I update a list in StateFlow (and change Compose View) without manually generating a new one just to modify one value in the list?

I have a lazyColumn of todo item data class TodoItem(val id: Int, val title: String, var urgent: Boolean = false) class AppViewModel : ViewModel() { private var todoList = mutableListOf( ...
Elye's user avatar
  • 57.1k
2 votes
1 answer
428 views

Android Jetpack Compose rememberSystemUiController() doesn't observe mutableStateOf()

I'm trying to achieve a hide/show functionality for status bar in an AbstractComposeView class MyView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr:...
Gonki's user avatar
  • 653
2 votes
1 answer
211 views

How to properly use mutability in Jetpack Compose to update Text when a value in a companion object is changed? (Kotlin)

EXPLANATION: I have a budget screen the Home.kt class basics are here: @Composable fun Home(navController: NavController) { var currentBalance = Budget.currentBalance Column( /* ... */...
keegaroo65's user avatar
1 vote
2 answers
1k views

Boolean State in compose is changing before the variable I put after it get's assigned

So I have Two ViewModels in my Calculator App in which I all reference in my Compose NavGraph so I can use the same ViewModel instance. I set a Boolean State(historyCheck) in the first ViewModel and I ...
Daniel Iroka's user avatar
1 vote
2 answers
494 views

Updating item in a mutableStateList is not triggering recomposition in UI (LazyColumn)

I have been scratching my head over this problem. I have a data class representing items that can be selected(or unselected). data class FilterItem( val name: String, val isSelected: ...
Ayush Patel's user avatar
1 vote
1 answer
238 views

MutableStateOf of mutableList not updating

Why my mutableStateOf of mutableList not updating? val checkedList by remember { mutableStateOf(MutableList(list.size) { false })
Slava's user avatar
  • 525
1 vote
1 answer
202 views

WearOS compose error: "java.lang.NoSuchMethodError: No static method mutableStateOf(J)Landroidx/compose/runtime/MutableLongState" [duplicate]

I wanted to start programming a wearOS app, so I just created an new project. But when I started the emulator to check if everything works, the default "hello world" application crashed and ...
FloTec09's user avatar
1 vote
1 answer
1k views

Compose UI not updating the state after updating the view model

I am trying to update a compose UI view based on the state changes in the view model, below is my code Initially i am making assigning and doing operation by the default value from view model to a ...
arun's user avatar
  • 175
1 vote
0 answers
328 views

Compose Android - Update a Item from list without page refresh

I have a LazyColumn list which holds user Items and I have populated the list Item view no issue on that, in here say I need to update a view from the Item like updating the user profile picture ...
arun's user avatar
  • 175
1 vote
0 answers
297 views

Android, Jetpack Compose - Composable function not getting refreshed

I am new to Android Jetpack compose. All i want to do is to update data in UI when it gets from API. Here is my Composable function: @Composable fun getCurrentWeather(lat : Double, long : Double, nc : ...
kinza's user avatar
  • 545
0 votes
1 answer
59 views

Jetpack Compose: Surface makes state is persisting without remember

im currently experiencing with jetpack compose states. Check out this composable: @Composable fun CounterWithoutRemember(reset: MutableState<Boolean>) { val count = mutableStateOf(0) ...
Kakaranara's user avatar
0 votes
1 answer
417 views

Jet Pack Compose Mutable List Updating With Mutable State list Problem

//declared in activity val statebilledproducts = viewModel.listBilledProducts //declared in viewmodel class OrderViewModel : ViewModel() { private val _listBilledProducts = mutableStateListOf<...
Mohamed Roshan's user avatar
0 votes
2 answers
95 views

Why snapshotFlow is trigged with MutableState as property delegate?

I have a situation with the snapshotFlow recently when trying to observe changes from a MutableState. Here is the snippet val searchQuery = mutableStateOf("") snapshotFlow { searchQuery }....
Thái Quốc Toàn's user avatar
0 votes
1 answer
36 views

How update state with copy function

My Ui state data class LoginUiState( val loginModel: LoginModel = LoginModel(), ) : UiState My ViewModel @HiltViewModel class LoginViewModel @Inject constructor() : BaseViewModel<LoginUiState&...
Yurii Dekhtiar's user avatar
0 votes
2 answers
118 views

How to use multiple mutableState in one compose screen

I have three api in ViewModel that are below. API for UserList API for DeviceList API for EventList All api have three state (Loading, Success, Error) I have to show all three info on Dashboard. ...
user2659769's user avatar
0 votes
1 answer
91 views

Is passing mutablestate to composable function optimal?

Like this : @Composable fun TextEdit(textState: MutableState<String>) { val text by textState TextField(onValueChange = { text = it }, value = text) } Is it optimal for ...
MH-Rouhani's user avatar
0 votes
1 answer
48 views

printing mutableState parameters

I have a class Plan() that has the parameter "val changeNumber : MutableState<Double?>". as in Plan( ... val changeNumber : MutableState<Double?> ... ){} I want to display this ...
IrrGuy's user avatar
  • 15
0 votes
1 answer
422 views

Variable not updated in compose

I have a class in Kotlin (Jetpack compose) with a variable title and an exoplayer that updates the title. class Player{ var title by mutableStatOf("value") .... title= "new value" ...
sigjak's user avatar
  • 179
0 votes
4 answers
1k views

Listen to changes in only particular object in a StateFlow of type List?

How to listen to only a particular element in the MutableStateFlow of type list? If we listen to the entire list, then all the Views that are listening to the list if changed would rebuild themselves ...
Muhammad Haroon's user avatar
0 votes
1 answer
494 views

Text and Button Color not updating when MutableState object changes

For the below code, I'm trying to get the selectedColorsText to update whenever a user clicks on a button. The button background should then turn black and the text inside it white once selected. If ...
Vaz's user avatar
  • 429
0 votes
1 answer
1k views

Attempt to invoke interface method on a null object reference in kotlin

After implementing viewmodels to jetpack compose app when I running the app it's showing a error :- Attempt to invoke interface method 'boolean java.util.Set.contains(java.lang.Object)' on a null ...
Monibur Haque's user avatar
0 votes
0 answers
3 views

combining multiple mutablestates

just started picking up Compose MP and have been running into difficulty combining 2 sources of mutablestates to a new mutablestate or flow within a viewmodel. per documentation https://developer....
Shay_A's user avatar
  • 17
0 votes
1 answer
22 views

Fragment which is not in foreground is not getting updated while observing a state object in activity scope viewModel

I am using Jetpack compose for my UI rendering. I have Fragment1 and Fragment2. I have a viewModel SharedViewModel which is defined in activity scope. When I send an update from Fragment2 which is in ...
Sarfaraz's user avatar
  • 366
0 votes
0 answers
78 views

What is more efficient mutableStateOf or mutableStateFlow?

I would to like to use MutableStateFlow in Compose components. var hasReadCode by remember { mutableStateOf(false) } var hasReadCodeFlow = remember { MutableStateFlow(hasReadCode) } I have ...
Takeshi567's user avatar
0 votes
0 answers
40 views

No virtual method Boolean call-mutableStateOf

Get the next error, when I try to create a properties variable in a actual fun java.lang.NoSuchMethodError: No virtual method Boolean$arg-2$call-$init$$arg-0$call-mutableStateOf$fun-$anonymous$$arg-0$...
Morozov's user avatar
  • 5,050
0 votes
0 answers
18 views

Android: Testing ViewModel with coroutines and states

I have been trying to understand how testing of ViewModel work in Android. I have the following view model class: @HiltViewModel class AllLaunchesViewModel @Inject constructor( private val ...
Bugs Happen's user avatar
  • 2,188
0 votes
1 answer
659 views

LazyColumn in jetpack compose does not recompose when list data changes, but forloop over data list works, I am not getting why and what is happening

I am developing a app using jetpack compose, and I am new to this UI framework, I want to display the categories amountSpent property. I am changing the amount spend in dialog and want to reflect the ...
Lokesh Chennamchetty's user avatar
0 votes
1 answer
231 views

What is the syntax to make a callback function variable mutable in Jetpack Compose?

I'm trying to make the following variable, selectedView, mutable so that I can set the current Composable View dynamically. var selectedView :@Composable () -> Unit = { testView() } I'm passing ...
J. Edgell's user avatar
  • 1,735
0 votes
0 answers
14 views

assertHistorySize() for State or MutableState in Android Test

I am used to use awaitValue + assertHistorySize to test how much a LiveData has received and what it has got. So I write the following code (only as an example): val dataObserver = viewModel.data()....
androoby's user avatar
0 votes
0 answers
34 views

Question about atomized modifications to SnapshotStateList

I am using SnapshotStateList to maintain a list of Elements to feed the compose UI. When I add, remove, and replace elements to this list, they trigger my LazyColumn component to recompose. this all ...
progquester's user avatar
  • 1,430
0 votes
1 answer
64 views

UI not updating properly on first launch of app Android Compose

I have the following code in my HomePageViewModel: private val _overallStitchCount: MutableStateFlow<Int> = MutableStateFlow(0) val overallStitchCount: StateFlow<Int> = ...
JamieRhys's user avatar
  • 276
0 votes
0 answers
39 views

UI not updating when viewmodel variable has changed jetpack compose

My variable is defined as follows in my view model: private val _overallStitchCount: MutableStateFlow<Int> = MutableStateFlow(0) val overallStitchCount: StateFlow<Int> = ...
JamieRhys's user avatar
  • 276
0 votes
0 answers
82 views

MutableStateFlow does not emitting value changes

Case is,I'm scanning hardware with NFC and getting texts from it,it has some steps to receive texts.for example: step 1 - starting scan, step 2 - scan in progress, step 3 - scan is almost finished, ...
Daviti Gogochishvili's user avatar
0 votes
1 answer
422 views

mutableStateListOf not doing recomposition on replacing some element in the list with targetsdk 33 and kotlin 1.7.20

Recomposition will happen only when you change the list itself. mutableStateListOf can only notify about adding, removing, or replacing some element in the list. Reference: Android Jetpack Compose ...
Android Developer's user avatar
0 votes
2 answers
859 views

How to update UI with a viewModel for byte arrays and lists in Kotlin/Jetpack Compose?

So the problem I am facing is that when the viewModel data updates it doesn't seems to update the state of my bytearrays: ByteArray by (mutableStateOf) and mutableListOf() When I change pages/come ...
Swifty's user avatar
  • 15
0 votes
0 answers
118 views

Test that value contained in MutableState is updated correctly

I have a viewModel that looks like this class PhotoViewModel( private val getPhotoUseCase: GetPhotoUseCase ) : ViewModel() { val photo: MutableState<PhotoItem?> = mutableStateOf(...
Gianluca Veschi's user avatar
0 votes
1 answer
85 views

Mutablestateof - State hoisting

What to do to manage one state in two functions? (openDialog) How to transfer openDialog state from ProductDialog() to AppBar()? I know I can make a separate class per state but I don't want to. @...
Krystian's user avatar
0 votes
1 answer
2k views

What is the proper way to update TextField string value after successfully loading data to pre-fill the TextField from database?

I am using Jetpack Compose, and it has occurred to me that I may be doing this incorrectly. Suppose we have a screen that allows us to edit a form's data, which has been saved locally using Room. ...
Team Chitoge's user avatar
0 votes
0 answers
217 views

MutableState value not getting updated in Observer block

I have a live data that I am observing in my fragment, in which I have to act on the result received from LiveData and update my MutableState which is used in a composable. I am not able to figure out ...
Ali_Waris's user avatar
  • 2,164