2

How can I solve this issue Content padding parameter it is not used in kotlin ? I made a dictionary app and I edited some codes and I have a problem like this Where should I add the content padding? how can i fix it?

@Composable
fun MainScreen(navController: NavController) {


    Surface(
        modifier = Modifier.fillMaxSize(),
        color = MaterialTheme.colors.background
    ) {

        Scaffold(
            topBar = {
                TopAppBar(
                    backgroundColor = bar,
                    title = {
                        Text(
                            text = "Main Menu",
                            modifier = Modifier.fillMaxWidth(),
                            color = Color.White,
                            fontSize = 22.sp
                        )
                    },
                    navigationIcon = {
                        IconButton(
                            onClick = { navController.navigate(Screen.SearchScreen.route) }
                        ) {
                            Icon(
                                painter = painterResource(id = R.drawable.ic_look_for_96),
                                contentDescription = "search",
                                tint = Color.Unspecified,
                            )
                        }
                    }
                )
            }
        ) {
            gridView(navController)   // problem is hear
            
        }

    }
}

enter image description here

Thales Isidoro
  • 1,753
  • 1
  • 5
  • 19
NewPartizal
  • 604
  • 4
  • 18

1 Answers1

6

This problem is not actually an error that will prevent your application from running, and it is even possible to ignore it, however if you ignore and do not use the padding provided by the Scaffold it may happen that components inside the Scaffold are overlapped by Scaffold components, for example the top bar.

To avoid this problem in the right way you will need something like this:

Scaffold(
    topBar = {
        // ...
    }
) { innerPadding -> // padding calculated by scaffold
    // it doesn't have to be a column,
    // can be another component that accepts a modifier with padding
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues = innerPadding) // padding applied here
    ) {
        // all content should be here
    }
}
Thales Isidoro
  • 1,753
  • 1
  • 5
  • 19