A simple Compose Multiplatform library to fill addresses, cities and countries in a form, based on Google Places API by Google https://developers.google.com/maps/documentation/places/web-service/autocomplete. For Android and IOS
Please generate a valid Google Places API key and add it to your project. You can find the instructions to generate key on Google docs: https://developers.google.com/maps/documentation/places/web-service/get-api-key Put your inside your project local.properties file:
api_key=<YOUR_API_KEY>
Then add the dependency to your project:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.ngallazzi:KMP-Places-Autocomplete:<LAST_VERSION>")
}
Just put PlaceAutoCompleteTextField composable within your app theme. Supported places are: City, Country, Address Want to use
@Composable
@Preview
fun App() {
MaterialTheme {
// Basic usage
PlaceAutoCompleteTextField(
label = "Please enter your city",
type = City::class,
onSuggestionSelected = {
// DO SOMETHING
}
)
}
}
@Composable
@Preview
fun App() {
MaterialTheme {
// Extended mode usage
PlaceAutoCompleteTextField(
label = "Please enter your city",
type = Address::class,
isExtendedModeActive = true,
onSuggestionSelected = {
// DO SOMETHING
}
)
}
}
// Complete parameters list
@Composable
fun PlaceAutoCompleteTextField(
modifier: Modifier = Modifier,
label: String = "",
text: String = "",
type: KClass<out Place>,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
isExtendedModeActive: Boolean = false,
enabled: Boolean = true,
readOnly: Boolean = false,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
languageCode: String = Locale.current.language,
textStyle: TextStyle = LocalTextStyle.current,
colors: TextFieldColors = OutlinedTextFieldDefaults.colors(),
shape: Shape = OutlinedTextFieldDefaults.shape,
onSuggestionSelected: (String) -> Unit = {},
)
Please feel free to open an issue if you have any feedback or suggestions. PRs are welcome too!
KMP Places Autocomplete is brought to you by these contributors.
This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the LICENSE.md file for details