How to pass object in navigation in jetpack compose?

As per the Navigation documentation: Caution: Passing complex data structures over arguments is considered an anti-pattern. Each destination should be responsible for loading UI data based on the minimum necessary information, such as item IDs. This simplifies process recreation and avoids potential data inconsistencies. So, if it is possible avoid passing complex data. More official … Read more

How to change text field cursor position in jetpack compose

We can use TextFieldValue to change cursor position Initialise the TextFieldValue just like this var textFieldValueState by remember { mutableStateOf( TextFieldValue( text = “” ) ) } after initialising it set the TextFieldValue just like the below OutlinedTextField( value = textFieldValueState, onValueChange = { textFieldValueState = it }, … ) To append additional text and … Read more

How can I detect keyboard opening and closing in jetpack compose?

Update With the new WindowInsets API, it gets easier First, to return the correct values, you need to set: WindowCompat.setDecorFitsSystemWindows(window, false) Then to use Keyboard as a state: @Composable fun keyboardAsState(): State<Boolean> { val isImeVisible = WindowInsets.ime.getBottom(LocalDensity.current) > 0 return rememberUpdatedState(isImeVisible) } use example: val isKeyboardOpen by keyboardAsState() // true or false ps: I’ve tried … Read more

Jetpack Compose – How can we call a @Composable function inside an onClick()

So you’re right, composable functions cannot be called from within onClicks from either a button or a modifier. So you need to create a value like: private val showDialog = mutableStateOf(false) When set to true you want to invoke the composable code, like: if(showDialog.value) { alert() } Alert being something like: @Composable fun alert() { … Read more

textAllCaps in jetpack compose

There’s not such property, but you can create it by yourself: @Composable fun CapsText( text: String, modifier: Modifier = Modifier, color: Color = Color.Unspecified, fontSize: TextUnit = TextUnit.Unspecified, fontStyle: FontStyle? = null, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, textAlign: TextAlign? = null, lineHeight: TextUnit = … Read more

Sharing viewModel within Jetpack Compose Navigation

Consider passing your activity to viewModel() fun as viewModelStoreOwner parameter since ComponentActivity implements ViewModelStoreOwner interface: val viewModel: ConversionViewModel = viewModel(LocalContext.current as ComponentActivity) This code will return the same instance of ConversionViewModel in all your destinations.

Where can I put the `suppressKotlinVersionCompatibilityCheck` flag?

I have the same problem with message: e: This version (1.0.0-alpha11) of the Compose Compiler requires Kotlin version 1.4.21-2 but you appear to be using Kotlin version 1.4.21 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don’t say I didn’t warn you!). Adding compiler args solved my problem: “-P”, … Read more

ViewModels creation is not supported in Preview

You could use an approach that looks like this which will show up in the recommended video bellow: @Composable fun TestView( action: MainActions, viewModel: OnboardViewModel = getViewModel() ) { TestUI(onClick = viewModel.clickMethod()) } @Composable fun TestUI(onClick: () -> Unit) {} @Preview @Composable fun TestUIPreview() { MaterialTheme() { TestUI(onClick = {}) } } There is a … Read more

how to change statusbar color in jetpack compose?

Step 1 (add dependency) => version may change implementation “com.google.accompanist:accompanist-systemuicontroller:0.27.0” Step 2 => inside theme.kt file change the colors according to your need in the functions below. val systemUiController = rememberSystemUiController() if(darkTheme){ systemUiController.setSystemBarsColor( color = Color.Transparent ) }else{ systemUiController.setSystemBarsColor( color = Color.White ) } Step 3 => ON systemUiController you can access all types of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)