Skip to content
Advertisement

Persist dark theme setting and apply in vaadin 14

Hello I want to apply the dark theme at the login of the user in Vaadin 14. But it does not work when i call the toggle function programmatically. I was following this example:

https://vaadin.com/learn/tutorials/toggle-dark-theme

The setting is already persisted, but how can i apply the theme setting? It works only when the trigger comes from a request thread. Here is my code:

JavaScript

The method gets called from the change theme button.

Advertisement

Answer

You can read the value in the onAttach method. Here is a full example class which uses a cookie for storage:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement