We are in the process of migrating our app from XML to compose and migrated a lot of areas in the app.
right now we need to implement Autocomplete from Google Places to one of our Compose screens which helps with a fragment
and whenever we try to invoke it we get the following error
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
and this is our current code inside our Compose screen.
@Composable
fun Autocomplete(fragmentManager: FragmentManager) {
Card(
modifier = Modifier
.fillMaxWidth()
) {
AndroidViewBinding(
factory = FragmentPlaceAutocompleteBinding::inflate,
modifier = Modifier
.fillMaxSize()
) {
val autocompleteFragment =
fragmentManager.findFragmentById(autocompleteFragment.id) as? AutocompleteSupportFragment
autocompleteFragment?.let {
// Specify the types of place data to return.
autocompleteFragment.setPlaceFields(listOf(Place.Field.ID, Place.Field.NAME))
// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment.setOnPlaceSelectedListener(object : PlaceSelectionListener {
override fun onPlaceSelected(place: Place) {
// TODO: Get info about the selected place.
Log.i("TAG", "Place: ${place.name}, ${place.id}")
}
override fun onError(status: Status) {
// TODO: Handle the error.
Log.i("TAG", "An error occurred: $status")
}
})
}
}
}
}
Theme.MaterialComponentsas itsparent?