Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unresolved reference: padding" even after importing layout.padding

So i was trying to get some text modifier with padding and it was all going good until I imported androidx.compose.foundation.layout.padding and the error on Modifier.padding(10.dp) didnt disapear, i tried searching if the import is moved/deprecated but i didnt see any changed releated to it. It also tells me the import isnt used so im really confused.

I use:
Android Studio - Arctic Fox 2020.3.1 canary 1
Kotlin Plugin - 1.4.10-Studio4.2-1\

My full code:

package com.example.weather

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.dp
import androidx.ui.tooling.preview.Preview
import com.example.weather.ui.ExampleWeatherTheme
import java.lang.reflect.Modifier

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ExampleWeatherTheme {
                Surface(color = MaterialTheme.colors.background) {
                    Column(modifier = Modifier.padding(10.dp)) {
                    FeelsLike(50)
                    }
                }
            }
        }
    }
}

@Composable
fun FeelsLike(feelstemp: Int) {
    Text(text = "Feels Like: $feelstemp°")
}

@Composable
fun Temperature(temp: Int) {
    Text(text = "$temp")
}

@Preview(showBackground = true)
@Composable
fun BasicPreview() {
    ExampleWeatherTheme(darkTheme = true) {
        FeelsLike(50)
    }
}
like image 535
ender1324 Avatar asked Nov 28 '22 12:11

ender1324


1 Answers

This is your issue:

import java.lang.reflect.Modifier

You are importing the wrong Modifier class. It happened to me and the error can be quite missleading. Change the import to:

import androidx.compose.ui.Modifier
like image 197
Abdelilah El Aissaoui Avatar answered Dec 04 '22 01:12

Abdelilah El Aissaoui