Questions tagged [viewmodel]
A view model or viewpoints framework is a framework which defines a coherent set of views to be used in the construction of an architecture. A view is a representation of a whole system from the perspective of a related set of concerns.
viewmodel
4,953 questions
0
votes
1
answer
78
views
Getting "None of the following candidates is applicable" when trying to use LiveData list in itemsIndexed in LazyColumn
Relvant code in ViewModel:
val allFoods: LiveData<List<Food>> = repository.allFoods.asLiveData()
and MainActivity:
...
Best practices
4
votes
5
replies
145
views
View model vs bloc in Flutter
As per MVVM architecture, I have to use a view model to separate data layer from UI. Can I instead use a Bloc for this purpose? What are the criteria to use one versus the other? Could you please ...
Best practices
0
votes
2
replies
61
views
Should a ViewModel live as long as the entire app? ViewModel inside Scaffold with BottomSheet + Google Maps
I am building a Jetpack Compose app that uses a Scaffold with a persistent bottom sheet.
The main content of the Scaffold show ...
Best practices
0
votes
3
replies
66
views
Add a NotMapped field to my model or create a view model to interface between the model and view?
I come from a MVVM in WPF background moving towards ASP.NET MVC. I have a model that is composed of another model called Message, like so:
...
0
votes
1
answer
104
views
Should I always initialize a viewmodel at the start? [closed]
Should I always initialize a viewmodel in the Activity, before onCreate() even, if it is needed later in the flow?
I do not know and am concerned if initialization of all the viewmodels right at the ...
1
vote
1
answer
96
views
Differences between long-running Flow processing with transform() and flatMapLatest()
I have a data stream coming from the server. The server does not provide any information about when the next piece of data will arrive. I have a Flow in my ...
0
votes
1
answer
53
views
Android ViewModel setValue function get stuck
To process the live data for signals, I defined following class SignalsViewModel and when I call the updateSignals function, it get stuck and doesn't run the next command.
I create the ...
1
vote
1
answer
207
views
Differences and best practices for using ViewModels in XML vs Jetpack Compose
I’m working on Android and I have some doubts about how to properly manage ViewModels depending on the type of UI I’m using (XML with Activities/Fragments vs Jetpack Compose).
Currently, my main ...
-6
votes
1
answer
138
views
SwiftUI alert @Binding view model isn't found in my view
I'm getting an Xcode error:
Cannot find $loginVM in scope.
I here's the simplified viewModel
...
1
vote
1
answer
148
views
C# WPF strict MVVM: Basic TreeView SelectedItem ViewModel Problem
I’m trying to bind the SelectedItem of a WPF TreeView to a property in my MainViewModel in a pure MVVM setup (no code-behind).
Since TreeView.SelectedItem is not a dependency property, I created an ...
1
vote
1
answer
75
views
pointerInput in Canvas resets ViewModel's state to its previous value
I have a composable which uses Canvas to draw tasks on a clock-like dial. The tasks are read from a ViewModel state, which in turn loads them from a database. The list of tasks varies depending on the ...
0
votes
1
answer
58
views
What is the right way to instantiate a ViewModel inside a Tab Fragment and scope it to the parent navigation destination?
I'm using Navigation Component + Hilt DI. I have a Navigation Destination Fragment which hosts a viewpager with 2 fixed fragments. What is the right way to Instantiate the ViewModels within those ...
0
votes
1
answer
110
views
How to change a button control within a Collection View in Maui
How do I access the button within a collection view to stop and start a timer on it? The sender is a UserItem but I want to change the button within the same collection view.
XAML Code (Collection ...
0
votes
0
answers
92
views
Jetpack Compose / Hilt MVI: ViewModel state not reset when closing and reopening dialog
I’m building a Jetpack Compose screen using an MVI pattern (ViewState / ViewEvent / ViewEffect) and Hilt for DI. I have a modal dialog with an input field for a name. The dialog’s composable looks ...
1
vote
1
answer
75
views
How to redirect with viewmodel
In a GET action method, based in some condition, I need to either return the view, or redirect to another action method that receives a view model via POST. This second action method view is strongly ...
0
votes
1
answer
51
views
Get ViewModel from onDraw Class
I create a class to draw random elements in a fragment, I need pass a list of elements already store in ROOM database with a Dao and Repository class.
ViewModel has a simple function to get all data
...
0
votes
0
answers
103
views
Trying to act on objects from a separate view SwiftUI SceneKit macOS 'cannot find ** in scope'
I have an app using SceneKit in a SwiftUI framework, and I am trying to properly organise my views by defining a separate view for the interface panel as an ZStack overlay.
I have moved the buttons (...
1
vote
1
answer
227
views
How to fix "Cannot create an instance of class ViewModel" when using Hilt?
I am doing a JetPack Compose course and I am trying to run an example project showcasing use of ViewModel together with Hilt.
...
0
votes
1
answer
75
views
Unresolved reference: ViewModelScope
I'm trying to run the example program at https://developer.android.com/kotlin/coroutines#examples-overview in Android Studio Iguana:
...
1
vote
2
answers
58
views
5
votes
1
answer
252
views
Why is initialValue needed in collectAsStateWithLifecycle for StateFlow?
I have a ViewModel that exposes a StateFlow representing the UI state of a book list:
...
3
votes
0
answers
336
views
Using ViewModels in React Native (instead of Redux)
State management in React Native is a well-debated topic, with Redux often being the default choice. However, for developers coming from native mobile development (Kotlin/Swift), Redux can feel ...
0
votes
0
answers
81
views
Mockito can only mock non-private & non-final classes, but the root cause of this error might be different
I want to write some UI tests for a Composable screen.
I constantly facing the same error again and again. The viewmodel cannot be mocked, even though I have declared the viewmodel class as open.
here ...
1
vote
1
answer
110
views
java.lang.IllegalStateException: Failed to find type for when decoding androidx.lifecycle.SavedStateHandle@8019b8e
Hello I am receiving the error in the title based off the following code:
...
1
vote
0
answers
70
views
I cannot display a popup from a view model
I want to display a community toolkit popup from a view model. The type of popup I want is a message box where I can pass a string variable that is the message I want displayed. I followed this Learn ...
0
votes
0
answers
103
views
How to add a UserControl specific ViewModel but still reach the Dependency Property changed callback in WPF
I would like to create a WPF class library based on a TreeView to visualize JSON strings.
I define a JsonProperty ...
0
votes
1
answer
66
views
TextField's onValueChange doesn't modify view model state
TextField always get empty when I try to write in it.
My ViewModel:
...
0
votes
1
answer
112
views
Property Command from EventToCommandBehavior didn't work
I followed the steps from the accepted answer from this link.I did my "own implementation", but the command doesn't raise. Also, I did the same as the post said, but it didn't work.
Here is ...
1
vote
0
answers
156
views
Shared ViewModel with Type-Safe Navigation in a Multimodule Project
As the title suggests, I am trying to determine the best approach for implementing a shared ViewModel in a multimodule project.
Here is the approach I currently use:...
1
vote
1
answer
150
views
unresolved reference uiState = uiState.copy from a data class
I have a data class in my models library
...
1
vote
0
answers
93
views
Add lifecycle viemodel to build.gradle.kts does not resolve with AndroidStudio
I set up latest Android studio and all is up to date.
I want to add viewModel to the dependencies of the build gradle.
All is now in this Version.
...
0
votes
2
answers
141
views
WPF MVVM Not updating view
I am developing an application which needs a stopwatch. And I want to show the elapsed time using a textblock. My problem is, that the view is not updating, but I can use ICommands.
Here I assign the <...
-1
votes
1
answer
72
views
WPF control doesn't update when property is changed [closed]
I am developing a WPF app for my final university project (thesis). One of the goals is to be able to dynamically change the language of the UI. I suppose that it is not a very good idea to do it the ...
0
votes
1
answer
38
views
Data not updating in RecyclerView in a BottomSheetDialogFragment
I have a BottomSheetDialogFragment containing a RecyclerView in my Android app. The data for the ...
0
votes
1
answer
50
views
How to get the notification text from the ViewModel?
My application is going to get a new string from the ViewModel every few hours and show it to the user as a notification text. The problem is that I don't know how to get the string from the ViewModel ...
1
vote
0
answers
265
views
Create HiltViewModel with custom ViewModelStoreOwner
I have this compose code who works perfectly:
...
1
vote
2
answers
170
views
How do I handle a function that is calling a repository and also being used in two separate ViewModels
I have two ViewModels that contain the same function. The function calls an interface/repository to retrieve data from a database, and the function then manipulates the data.
It is my understanding ...
3
votes
1
answer
107
views
Hilt injection order inconsistency leading to NullPointerExceptions in Compose ViewModel
I'm currently working on an application using Compose and Hilt, and occasionally (less than 10 times out of 1000 according to my automated tests), the order of calls to my ViewModel differs, leading ...
0
votes
1
answer
29
views
How am i supposed to do Unit Test for a viewmodel that have a function to get it's token from api?
i've been working on this assignment of mine. to make a unit test on a viewmodel. but the viewmodel actually fetch token from api. is making a dummy for the token right? also i have a problem to make ...
0
votes
1
answer
64
views
WPF Multidimensional Complex Object Model Binding and Wrapping for MVVM
I am a bit new to MVVM, I have a complex model List<List<SomeClass>>, lets call it a board, I want to bind it to a ...
0
votes
1
answer
154
views
How to create different viewmodel instance for fragments in viewpager scoped to parent fragment with Hilt
I have a fragment HomeFragment which is part of the app navigation graph. Within FragmentHome I have a viewpager with 3 fragment ...
0
votes
1
answer
55
views
How to create a koin module for interface
I have an abstract class:
...
0
votes
0
answers
68
views
NavigationViewModel gets unexpectedly cleared when a screen is popped from the back stack
Let's assume I have two screens:
Screen A
Screen B.
When I send a NavigationUiEvent.ShowScreenB to the NavigationModel, the <...
1
vote
3
answers
364
views
viewModel on Kotlin Multiplatform?
How do I import androidx.lifecycle.viewmodel.compose.viewModel on Kotlin Multiplatform (iOS, web, desktop, Android)?
Attempts:
...
0
votes
1
answer
46
views
How do I get access to a content page's control from its view model that it was initially bound to?
What I'm looking to do is create and write all my methods in my view model file, and only place code in the code-behind file for functions that are automatically generated like ...
0
votes
1
answer
40
views
ViewModel's LiveData variable is empty value and not the desired value from Flow
I am trying to make a simple app that uses firestore, that just insert the token of devices and fetch the names corresponding to that token. When I tried to fetch "name" value , the flow in ...
1
vote
1
answer
286
views
How to observe changes in a List when the ViewModel is in Java and the UI is in Jetpack Compose (Kotlin)
I am migrating an application from View to Compose. The application was written in Java so I need to migrate the UI to Kotlin.
I prefer to do it as gradually as possible so I'm leaving the ViewModel ...
0
votes
1
answer
59
views
Storing current data
All the data comes from the server in bulk. I cannot influence its volume. Therefore, to reduce the number of requests, I store this data in a single ViewModel, which I share on all screens. I ...
0
votes
1
answer
115
views
How can I fix the issue of StateFlow values not updating?
How can I fix the issue of StateFlow values not updating?
The value of StateFlow is not assigned to the BoardRequestDto object.
The latest value of StateFlow is not properly collected in the ...
1
vote
2
answers
84
views
Submitting a POST using a ViewModel
I'm creating a website where you can Create an event for a game.I have a Create Page. The page has a GameID field when creating a new Event. I'm attempting to use a ViewModel so that I can display the ...