skip to Main Content

I have my code setup as below:

What would I need to change here to not have to add the @SuppressLint?

2

Answers


  1. If you wants to remove @SuppressLint("UnusedMaterialScaffoldPaddingParameter") warning then you have to add PaddingValues to content in Scaffold . you can write like this👇

                 Scaffold(
                        topBar = { MyTopBar() }
                    ) { paddingValues ->
                        Column(modifier = Modifier.padding(paddingValues)) {
                            // write your content here
                        }
                    }
    

    Basically PaddingValues is to provide padding to the content ( always apply paddingValues to parent composable function ).

    Login or Signup to reply.
  2. Use the paddingValues on next content, it is there exactly to calculate the correct screen display for the content to come in the compose tree.

    If you don’t use it, your screen will appear behind scafold elements, like the topbar or the bottombar.

    Content without innerPadding set:

    without innerPadding

    Content with innerPadding set:

    with innerPadding

    Here is an example of how i use it:

    { innerPadding ->
                NavHost(
                    navController,
                    startDestination = startDestination.route,
                    Modifier.padding(innerPadding)
                ) {
                    currentScreen = navigationItems.find {
                        it.route == currentDestination?.route
                    } ?: startDestination
                    composable(Screen.NotesList.route) {
                        NotesListScreen(
                            modifier = Modifier
                                .fillMaxSize()
                                .padding(horizontal = MaterialTheme.spacing.medium)
                        )
                    }
                    composable(Screen.Bin.route) {
    
                    }
                }
            }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search