title: How to change theme in Flutter?
body: <p>So I'm trying here to get the current theme, if it's light or dark.
  So I can change widget color accordingly..
  However, it doesn't work, I used if statment to know when it's dark mode..
  but it's always False ..
  This is the code.. btw it switch between dark &amp; light theme..
  but when i try to get current theme.. even if the theme changed to dark..
  the if statments always show false...</p>
  <pre><code>class MyHomePage extends StatefulWidget {
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    @override
    Widget build(BuildContext context) {
  
      bool darkModeOn = MediaQuery.of(context).platformBrightness == Brightness.dark;
      Color containerColor;
      if (darkModeOn == true) {
        containerColor = Colors.blueGrey;
        print(&quot;----------------&quot;);
        print(&quot;dark mode ON&quot;);
        print(&quot;----------------&quot;);
      } else {
        containerColor = Colors.deepPurple;
        print(&quot;LIGHT mode ON&quot;);
      }
  
      return Scaffold(
        floatingActionButton: FloatingActionButton.extended(
            onPressed: () {
              //----switch theme---
              currentTheme.switchTheme();
            },
            label: Text(
              &quot;Switch theme&quot;,
              style: TextStyle(
              ),
            ),
          icon: Icon(Icons.color_lens_outlined),
        ),
        appBar: AppBar(
          title: Text(&quot;DarkXLight&quot;),
        ),
        body: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Expanded(child: Container(
                color: containerColor,
              ),
              ),
              Expanded(child: Container(
                color: Colors.amber,
              ),
              ),
            ],
          ),
        ),
      );
    }
  }
  </code></pre>