Issue
I recently started working with Jetpack Compose. I've got the following composable:
@Composable
fun SearchScreen(navController: NavHostController) {
Scaffold(
topBar = { SearchBar() },
content = {
Column(modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())) {
Text(stringResource(id = R.string.genreFilter))
Row(
modifier = Modifier
.horizontalScroll(rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
// some nested Composables
}
}},
)
}
But with this code as-is, the whole code within content = {...}
is being underlined in red saying Jetpack Compose: Content padding parameter it is not used
. I already read in this Stackoverflow Post that actually, PaddingValues
only are provided in a Scaffold if the bottomBar
is set, which obviously is not the case here. So I do not understand why I am getting this error.
Note: The app actually does use a BottomNavigation
, but not within the Composable
that I showed above. Can it be that this is still somehow propagated here?
Solution
Since Compose 1.2.0 (currently in alpha) it's required to use padding parameter, passed into Scaffold
content
composable. You should apply it to the topmost container or other view in content
:
content = { padding ->
Column(
modifier = Modifier
.padding(padding)
// ...
This is done to prevent layout problems, for example, when the scaffolding has a bottom bar, without the use of this padding part of your view will be under the bar.
You can always suppress it with @SuppressLint("UnusedMaterialScaffoldPaddingParameter")
, but I would recommend doing this only when you know exactly what you are doing.
Answered By - Pylyp Dukhov
Answer Checked By - Terry (JavaFixing Volunteer)