Is it possible to allow the user to toggle between dark mode and light mode in a Xojo web application?
I wish to give the user the ability to switch.
Xojo advertises drop-in Bootstrap 5 themes, but that’s more when you push the compile button rather than when you push the preferences button once the application is already running.
The only way I can think to go around this is to have two parallel versions of the application running on the same web server and routing the traffic to the dark side or to the light side. ( Star Wars references are hereby preempted in any comments.)
It should be automatic though, so even if you had two servers, they’d still show what the user’s browser requests and therefore the same, unless you’re thinking about using two separate themes. If that’s your goal, I seem to remember that we added a way for developers to use different themes at runtime on user by user basis, but I’m not 100% sure any more.
The following code in a Checkbox will switch between light and dark modes:
if me.Value then
me.ExecuteJavaScript("document.body.setAttribute('data-bs-theme', 'dark');")
Else
me.ExecuteJavaScript("document.body.setAttribute('data-bs-theme', 'light');")
end if