title: How to change the app global primary color in flutter on button press?
body: <p>How to change the app global primary color in flutter on button press to switch between 2 themes with 2 different primary colors?</p>
  <p>ex:</p>
  <pre><code>import 'package:flutter/material.dart';
  
  void main() {
    runApp(const MyApp());
  }
  
  class MyApp extends StatefulWidget {
    const MyApp({Key? key}) : super(key: key);
  
    @override
    State&lt;MyApp&gt; createState() =&gt; _MyAppState();
  }
  
  class _MyAppState extends State&lt;MyApp&gt; {
    final darkColorForLightTheme = 0xff242f60;
  
    final lightColorForDarkTheme = 0xff03DAC5;
  
    @override
    Widget build(BuildContext context) {
      var isDark = true;
      var primaryColorHex = (isDark ? lightColorForDarkTheme : darkColorForLightTheme);
      var primaryColor = Color(primaryColorHex);
      return MaterialApp(
        title: 'Welcome to Flutter',
        theme: ThemeData.light().copyWith(
          primaryColor: primaryColor,
          brightness: Brightness.light,
          backgroundColor: const Color(0xFFE5E5E5),
          dividerColor: Colors.white54,
          colorScheme: ColorScheme.light(primary: primaryColor),
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text('Welcome to Flutter'),
          ),
          body: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                const Text('Hello World'),
                MaterialButton(
                    color: primaryColor,
                    onPressed: () {
                      setState(() {
                        isDark = !isDark;
                      });
                    },
                    child: const Text('Change app primary color')),
              ],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>