WidgetKit & dark mode

Hi ... its any way to detect and switch style to dark mode...
Answered by jcgoforth in 626136022
Depending on what you want to do, you don't even have to do that. The simplest way to handle light/dark mode is to define any color you want switch in the asset catalog (something like "Assets.xcassets")and set "Appearances" for the color to "Any, Dark". You can do this for as many colors as you need. You can then use those colors by name using something like: Color("WidgetBackground"). The widget will then automatically switch when the system theme changes.
You can use @Environment(\.colorScheme) var colorScheme as in any other SwiftUI app!
Accepted Answer
Depending on what you want to do, you don't even have to do that. The simplest way to handle light/dark mode is to define any color you want switch in the asset catalog (something like "Assets.xcassets")and set "Appearances" for the color to "Any, Dark". You can do this for as many colors as you need. You can then use those colors by name using something like: Color("WidgetBackground"). The widget will then automatically switch when the system theme changes.
WidgetKit & dark mode
 
 
Q