google-developer-training / basic-android-kotlin-compose-training-mars-photos

Solution code for Android Basics in Kotlin course
https://developer.android.com/courses/android-basics-kotlin/course?gclid=CjwKCAjw4c-ZBhAEEiwAZ105RTyT-iaLHzrhMBUXdMhO230ZDwOwxxI2x4RgK8DwBxK8t1h0wmU_QxoCi4YQAvD_BwE
Apache License 2.0
72 stars 66 forks source link

Add repository and Manual DI #20

Open hhyeok1026 opened 1 year ago

hhyeok1026 commented 1 year ago

URL of codelab: https://developer.android.com/codelabs/basic-android-kotlin-compose-add-repository?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-5-pathway-2%3Fauthuser%3D1%26hl%3Dko%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-add-repository#5

In which task and step of the codelab can this issue be found?

  1. Add repository to ViewModel

Describe the problem

  1. Add repository to ViewModel (6. Open the MainActivity.kt file and create a variable viewModel of type MarsViewModel.)

In the codelab description The viewModel is created in MainActivity.

However,

  1. Add repository to ViewModel (8. Update the code to pass variable viewModel as an argument to the MarsPhotosApp composable)
MarsPhotosTheme {
     val viewModel: MarsViewModel =
         viewModel(factory = MarsViewModel.Factory)
     MarsPhotosApp(viewModel)
}

MarsPhotosApp() is generating an error because there is no viewModel parameter.

In the solution code it is initializing marsViewModel inside the MarsPhotosApp composable function.