https://kotlinlang.org
Join Slack
Hello! I'm having some issues when trying to add custom headers to a `HttpServletResponse` within a ...
l

Leonardo Borges

almost 3 years ago
Hello! I'm having some issues when trying to add custom headers to a
HttpServletResponse
within a suspend function. The approach we are using now is not good, so we would like to find a proper solution:
@GetMapping("/users")
suspend fun getUsers(//...parameters, response: HttpServletResponse): List<UsersResource> {
    val users = userService.searchBy(//parameters)
    response.addPaginationHeaders(users.size)
    return users
}
For instance,
addPaginationHeaders
will be changed only for example purposes, as below:
internal fun HttpServletResponse.addPaginationHeaders(size: Int) {
    val uri = ServletUriComponentBuilder.fromCurrentRequest().toUriString()
    setHeaders("X-Count", size)
    //...other params
}
So, suspend function doesn't work (throws
java.lang.IllegalStateException: No current ServletRequestAttributes
). Instead, we have to place the function body within a
runBlocking
to make it work.
suspend fun getUsers(\\...parameters, response: HttpServletResponse) = runBlocking {
    //same code as above
}
Has anyone experienced this issue? Is there any solution besides
runBlocking
?
l
s
e
  • 3
  • 8
  • 329
Is there a way to navigate back inside a bottom sheet? I have 2 composables inside a bottom sheet. W...
s

Stephen Vinouze

about 3 years ago
Is there a way to navigate back inside a bottom sheet? I have 2 composables inside a bottom sheet. When I navigate to the second screen, the back button dismisses the bottom sheet instead of navigating back to the first screen. Navigation works well as long as the back button is not involved. Yet
BackHandler
inside the composables don’t get called 🤔
s
i
  • 2
  • 6
  • 329
Hi, is there a way to serialize an enum as the ordinal without adding SerialName for each key ?
a

Ayfri

about 3 years ago
Hi, is there a way to serialize an enum as the ordinal without adding SerialName for each key ?
a
e
  • 2
  • 3
  • 329
Hello, the code in the thread gives a warning. Is this intended behaviour or am I abusing Mockk?
k

Klitos Kyriacou

over 3 years ago
Hello, the code in the thread gives a warning. Is this intended behaviour or am I abusing Mockk?
k
e
  • 2
  • 2
  • 329
Is it possible to move Floating Action Button above keyboard when using Scaffold?
b

Benyam Seifu

over 4 years ago
Is it possible to move Floating Action Button above keyboard when using Scaffold?
b
t
  • 2
  • 2
  • 329
Is it possible to mock a suspend inline extension function? If so, how?
j

Joram Visser

almost 7 years ago
Is it possible to mock a suspend inline extension function? If so, how?
j
o
l
  • 3
  • 5
  • 329
has anyone used Coil to load `.webp` drawables? I am having a hard time making it animated.
a

André Tessmer

over 2 years ago
has anyone used Coil to load
.webp
drawables? I am having a hard time making it animated.
a
c
  • 2
  • 2
  • 328
When building an annotated string with `buildAnnotatedString` for a VisualTransformation for a TextF...
s

Stylianos Gakis

almost 3 years ago
When building an annotated string with
buildAnnotatedString
for a VisualTransformation for a TextField, I wanted some section of the text to be whatever the color already was, only with a lower alpha value. Best I found out how to do now was
// in composable context:
val mediumAlphaContentColor = LocalContentColor.current.copy(ContentAlpha.medium)
// Inside the visualTransformation not in a composable context
...
  buildAnnotatedString {
    append("")
    withStyle(SpanStyle(mediumAlphaContentColor))) {
      append("gray text")
    }
  }
}
But is there any API I can use to simply alter the alpha without changing the content color? Maybe in some span I am not gonna be using the LocalContentColor value and simply want to use whatever was there already. Maybe this isn’t possible though right?
s
j
  • 2
  • 3
  • 328
I'm trying to setup my Kotlin project to run in WSL, but I just get this error and have no clue on h...
j

jeggy

over 4 years ago
I'm trying to setup my Kotlin project to run in WSL, but I just get this error and have no clue on how to fix it.
j
c
  • 2
  • 23
  • 328
Is there a right way to use Jetpack Compose Navigation components with Koin?
s

Slava Glushenkov

over 4 years ago
Is there a right way to use Jetpack Compose Navigation components with Koin?
s
a
p
  • 3
  • 7
  • 328
Previous211212213Next

kotlinlang

A modern programming language that makes developers happier.

Powered by