Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import createRefs() for constraint layout

My Imports

Its asking me to import Focus request but i want to use the createRef() for Constraint layout reference

I'm using this version: "androidx.constraintlayout:constraintlayout-compose:1.0.0-rc01"

like image 1000
Abhilash R Avatar asked Oct 23 '25 17:10

Abhilash R


2 Answers

It's too late but I got the same problem and found the answer.

I forgot to surround createRefs by ConstraintLayout. It should be like this.

ConstraintLayout {
  val (button, text) = createRefs()

  Button(
    onClick = { /* Do something */ },
    modifier = Modifier.constrainAs(button) {
      top.linkTo(parent.top, margin = 16.dp)
    }
  ) {
    Text("Button")
  }

  Text("Text", Modifier.constrainAs(text) {
    top.linkTo(button.bottom, margin = 16.dp)
  })
}

and you should import this.

import androidx.constraintlayout.compose.ConstraintLayout

I hope this helps you

like image 164
vegcale Avatar answered Oct 26 '25 08:10

vegcale


When you want to write your "ConstraintSet" be careful not to add any other implementation of "androidx.compose

like image 31
DavidOli Avatar answered Oct 26 '25 07:10

DavidOli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!