1

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")
                    }
                })
            }
        }
    }

}
2
  • So does the theme of your activity use Theme.MaterialComponents as its parent? Commented Feb 16, 2024 at 15:15
  • yes parent="Theme.MaterialComponents.Light.NoActionBar.Bridge" Commented Feb 16, 2024 at 15:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.