Custom Theme not changing the application color

The Custom Theme implementation in my code is like this

#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Theme {
    pub background: Color,
    container_bg: Color,
    text: Color
}

impl Theme {
    pub const LIGHT: Self = Self {
        background: color!(255, 255, 255),
        container_bg: color!(214, 214, 214),
        text: Color::BLACK
    };

    pub const DARK: Self = Self {
        background: color!(32, 34, 37),
        container_bg: color!(54, 54, 54),
        text: Color::WHITE
    };
}

impl Default for Theme {
    fn default() -> Self {
        Self::LIGHT
    }
}


impl application::StyleSheet for Theme {
    type Style = Theme;

    fn appearance(&self, style: &Self::Style) -> application::Appearance {
        application::Appearance {
            background_color: style.background,
            text_color: style.text
        }
    }
}

And the App Struct is like this

pub struct App {
    theme: Theme
}

enum Message {
    ToggleTheme
}
// The update function inside the implementation
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
    match message {
        Message::ToggleTheme => {
            println!("Theme changed to {:?}", self.theme);
            if self.theme == Theme::LIGHT {
                self.theme = Theme::DARK
            } else {
                self.theme = Theme::LIGHT
            }
        }
    }
    Command::none()
}

it does print the theme change message but the theme doesn’t change

In your app you need to implement pub fn theme(&self) -> Theme and return your current theme.

Something like

pub(crate) fn theme(&self ) -> Theme {
        self.theme.clone()
}

and then pass that function (or as a closure if you wish) to the theme method.

It depends a bit on how you are running your application. I use a Daemon and so do it like

iced::daemon(CalculatorApp::title, CalculatorApp::update, CalculatorApp::view)
        .load(move || {
            window::open(window_settings.clone()).map(Message::MainWindowOpened)
        })
        .settings(settings)
        .subscription(CalculatorApp::subscription)
        .theme(CalculatorApp::theme)
        .run();

See the example for using a Sandbox