I currently have been using this Environment variable to adjust things for Dark and Light modes on my app.
@Environment(.colorScheme) var colorScheme
The problem I'm having is using that var to conditionally set a button style. This method works just fine.
if colorScheme == .dark {
Button("Create Account", action: {
}).buttonStyle(CinderDarkButtonStyle(geometry: geometry))
} else {
Button("Create Account", action: {
}).buttonStyle(CinderLightButtonStyle(geometry: geometry))
}
However doing it this way causes me to duplicate code all over the place on a relatively simple user interface. Whenever I attempt to do it this way I end up with errors stating that I have mismatched types.
Button("Create Account", action: {
//DO SOME ACTION
}).buttonStyle(
colorScheme == .dark ?
CinderDarkButtonStyle(geometry: geometry) :
CinderLightButtonStyle(geometry: geometry)
)
)? - Don