Dark Mode Theme not working

Hii,
I have tried below code to apply “Dark Mode” theme but is not working in ionic 3 and 4 also try in ionic 1 but the same result.

  • I tried the android system setting to select dark mode but when tried to below code result is false.

    // Use matchMedia to check the user preference
    const prefersDark = window.matchMedia(’(prefers-color-scheme: dark)’);

    toggleDarkTheme(prefersDark.matches);

    // Listen for changes to the prefers-color-scheme media query
    prefersDark.addListener((mediaQuery) => toggleDarkTheme(mediaQuery.matches));

    // Add or remove the “dark” class based on if the media query matches
    function toggleDarkTheme(shouldAdd) {
    document.body.classList.toggle(‘dark’, shouldAdd);
    }

  • In the above code, "const prefersDark " value always returns a false value

Please tell me anything wrong on my side.
Thanks you

1 Like

did you ever get this figured out? I am guessing there is no native support for dark mode on android yet. I have tried the provided solution as you did with no luck yet

I wonder what is that ‘shouldAdd’ in that code suppose to be?

Have you found a fix for this?