Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix Unresolved reference: dp?

Hello I have tried to find some help with this I'm using the correct import statement import androidx.compose.ui.Modifier but I get the error message e: /Users/lebo/AndroidStudioProjects/BasicsCodelab/app/src/main/java/com/example/basicscodelab/MainActivity.kt: (36, 68): Unresolved reference: dp

My code looks like this but when I add padding it stops working

package com.example.basicscodelab

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.basicscodelab.ui.theme.BasicsCodelabTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            BasicsCodelabTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("Android")
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String) {
    Surface(color = MaterialTheme.colorScheme.primary){
        Text(text = "Hello $name!", modifier = Modifier.padding(24.dp))
    }

}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    BasicsCodelabTheme {
        Greeting("Android")
    }
}

I tried updating my grade version and jetpack compose in the source gradle file and in the app gradle file and nothing has helped. I've been stuck for hours

like image 687
Lebo Avatar asked Sep 02 '25 10:09

Lebo


1 Answers

Import dp like this

import androidx.compose.ui.unit.dp
like image 59
Vika Avatar answered Sep 04 '25 09:09

Vika