35

I want to know what is Scaffold in jetpack compose with a BottomAppBar example can anyone help me Scaffold

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

1 Answers1

46

Scaffold allows you to implement a UI with the basic Material Design layout structure. Scaffold provides slots for the most common top-level Material components, such as TopAppBar, BottomAppBar, FloatingActionButton, and Drawer.

Something like:

   val scaffoldState = rememberScaffoldState()
   // Create a coroutineScope for the animation
   val coroutineScope = rememberCoroutineScope()


    Scaffold(
        scaffoldState = scaffoldState,
        drawerContent = { Text("Drawer content") },
        bottomBar = {
            BottomAppBar(cutoutShape = CircleShape) {
                IconButton(
                    onClick = {
                        coroutineScope.launch { scaffoldState.drawerState.open() }
                    }
                ) {
                    Icon(Icons.Filled.Menu, contentDescription = "....")
                }
            }
        },
        floatingActionButton = {
            ExtendedFloatingActionButton(
                text = { Text("Action") },
                onClick = { /* .... */ }
            )
        },
        floatingActionButtonPosition = FabPosition.Center,
        isFloatingActionButtonDocked = true,
        content = { innerPadding ->
            //....
        }
    )

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • scaffold is needed to create a skeleton structure on the ui side but Is scaffold always necessary? In which situations do we use or not use? – NewPartizal Mar 03 '23 at 08:39