1

I'm trying to display a profile screen using:

Scaffold(
    topBar = {
        DarkTopBar()
    },
    content = ProfileContent()
)

Where the ProfileContent() looks like this:

@Composable
fun ProfileContent() {
    Box(
        modifier = Modifier.fillMaxSize().padding(top = 96.dp),
        contentAlignment = Alignment.TopCenter
    ) {
        Text(
            text = "Good day!",
            fontSize = 48.sp
        )
    }
}

But I get the following error:

Type mismatch: inferred type is Unit but (PaddingValues) -> Unit was expected

What I have tried to solve this problem is to move the above function call inside the body:

Scaffold(
    topBar = {
        DarkTopBar()
    }
) {
    ProfileContent() //Moved here.
}

But Android Studio is complaining saying:

Content padding parameter it is not used

Can anyone help me?

Joan P.
  • 2,368
  • 6
  • 30
  • 63
  • Is this a warning or an error? "But Android Studio is complaining saying: Content padding parameter it is not used" – Abhimanyu Apr 25 '22 at 07:50
  • @Abhimanyu As I see, the app compiles, but why do I get this message? How can I overcome that? – Joan P. Apr 25 '22 at 07:53
  • "but do I get this message" can you explain where you are seeing this and if it is a warning or error. – Abhimanyu Apr 25 '22 at 07:53
  • @Abhimanyu Check [this](https://i.ibb.co/khWzc9y/1.png) out. – Joan P. Apr 25 '22 at 07:57
  • As the screenshot shows, it is a warning. If you have a value that you are not using, Android studio shows a warning. In this case, `Scaffold`'s `content` gives a `PaddingValue` and you are not using that. Hence the warning. You can ignore it unless you want to use the value. – Abhimanyu Apr 25 '22 at 08:04
  • @Abhimanyu Is there a way I can supress that warning? Thanks for taking the time to comment to my question. – Joan P. Apr 25 '22 at 08:05
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244178/discussion-between-abhimanyu-and-joan-p). – Abhimanyu Apr 25 '22 at 08:05
  • 2
    You can pass modifier, which is also recommended, in your ProfileContent() and use Scaffold's paddingValues as padding in this modifier. Like: `Scaffold( topBar = { DarkTopBar() } ) { ProfileContent(modifier = Modifier.padding(it)) }` **Or,** you can just ignore the message from Android Studio (which is not recommended) adding **@SuppressLint("UnusedMaterialScaffoldPaddingParameter")** – Ahsan Ullah Rasel May 25 '22 at 10:13

1 Answers1

-1

Your problem is that the content parameter of Scaffold should take a composable function. Here, you are not passing the function as an argument as you think you are, but instead actually calling the function. To fix put the function call inside a lambda for content like you did for topAppBar.

So change this:

Scaffold(
    topBar = {
        DarkTopBar()
    },
    content = ProfileContent()
)

To this:

Scaffold(
    topBar = {
        DarkTopBar()
    },
    content = {
        ProfileContent()
    }
)
Can_of_awe
  • 1,431
  • 1
  • 11
  • 17
  • I'm sorry but I get the exact same behaviour. Have you tried it? Please also note that I have the latest dependencies. Thanks anyway. – Joan P. Apr 25 '22 at 13:03