We created map view model, marker repository and Firebase module.
Now let's move to the Uber clone map.
And inside this composable function we need to test the code.
So testing add marker function.
Start with val view model.
It's of type map view model equals to Hillthe view model Hillthe view model function.
Retrieves the view model instance automatically uses Hillthe to create and inject dependencies into
it.
Makes sure it's tied to the life cycle of the current nav Backstack entry.
Like a screen because you write val view model, it's of type map view model compose knows which view
model you want, which is the map view model, and hilt will find the hilt view model annotation on
map view model.
See what dependencies it needs.
In the constructor, create and inject them.
So back to the map view model.
Here we have the marker repository.
Here it will create this repository and use it in order to make the code work smoothly.
The ViewModel returned is scooped the Composables nav and or navigation graph entry or the parent lifecycle
owner.
So when you navigate away, the ViewModel is cleared.
This line of code tells hilt hey hilt, please give me the map ViewModel for this screen with everything
it needs injected.
Okay, so back to the map ViewModel.
The only thing we need to inject is the marker repository.
This is a very important step in order to create the ViewModel and tell hilt that.
Go and create this function and and create an instance of map ViewModel and injective map marker repository.
Let's call the ViewModel dot add marker.
Here we need to pass four parameters.
Lat long.
This is for San Francisco, the marker name San Francisco on success.
What we need to do handle success.
Exception show an error message alt press enter to import that long.
And here we go.
You can make for example log dot v tag is the tag and marker added successfully.
Okay, this is how we handle the call of ViewModel and creation of it.
Let's test our application.
Run the app.
Here we go.
And the app crashes.
Let's see in the Logcat.
What is the error given component?
Mainactivity doesn't implement Interface dagger.
So what we need to do is going to is to go to main activity class and name it as and mark it as with
Android entry point annotation Alt+.
Enter Android entry point annotation marks and Android framework class so hilt can inject dependencies
into it.
It simply says hey hilt, I want to inject stuff here.
You put Android entry point annotation on any class where you want to inject fields with inject annotation
activities, fragments, services, broadcast receivers, jetpack compose, Composables and others.
So we put it on activities, broadcast receivers, services, fragments and in this case using Jetpack
Compose, we put it in the main activity.
When you add Android entry point annotation health generates code behind the scenes.
It sets up the dependency container for the Android component.
You can now use inject annotation to get dependencies without Android Entrypoint.
Hilt will not work and you'll get an error as I showed you.
Now let's run our application.
Also, the errors persist.
Scroll down and see.
Unable to start activity.
Main activity.
And did you forget to specify your application's class name in your manifests?
So here we need to create the hilt.
Activity must be attached to hilt Android application.
In the next video we're gonna solve this error.