Home > Software design >  Type mismatch. Required: Alignment.Horizontal Found: Alignment
Type mismatch. Required: Alignment.Horizontal Found: Alignment

Time:03-08

Context

I'm trying to create a FloatingActionButton at the bottom right part of a screen that allows you to scroll back up to the top of the screen (It's a screen with a scrollable list)

Code

FloatingActionButton(backgroundColor = MaterialTheme.colors.primary,
                    modifier = Modifier
                        .align(Alignment.BottomEnd)
                        .navigationBarsPadding()
                        .padding(bottom = 8.dp),
                    onClick = { coroutineScope.launch { listState.scrollToItem(0) } }) {
                    Text(text = "Up!")
                }

I get an error on .align(Alignment.BottomEnd)

Type mismatch. Required: Alignment.Horizontal Found: Alignment

I get this means the .align method expects Alignment.Horizontal type but BottomEnd is of type Alignment. How do I solve this?

CodePudding user response:

If you want to use Alignment.BottomEnd the FloatingActionButton must be in Box scope.

Use scaffold with floatingActionButton parameter instead it will place the button automatically in bottom right, like this:

Scaffold(
  floatingActionButton  = {
    FloatingActionButton()
  }
)

If you wanna change the place use floatingActionButtonPosition

  • Related