title: Flutter switch toggles off on its own
body: <p>I have created a flutter starter kit that allowes me to switch between themes in-app.</p>
  
  <p>Now this works great but there is a small issue.</p>
  
  <p>I have placed the switch button in the settings screen, 
  but when I go to another screen and then back to the settings screen 
  - it would seem that the switch button goes to Off mode on its own.</p>
  
  <p>I'm attaching an image and <a href="https://github.com/JaserJsk/flutter_playground/tree/master/gambit_app" rel="nofollow noreferrer">my code on github</a> so that you guys can see what I mean.</p>
  
  <p><a href="https://i.stack.imgur.com/NumGW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NumGW.jpg" alt="enter image description here"></a></p>
  
  <pre><code>class ThemeSwitchState extends State {
    bool switchControl = false;
  
    Future&lt;bool&gt; darkMode() async {
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
      return sharedPreferences.getBool("isDark");
    }
  
    @override
    Widget build(BuildContext context) {
      return FutureBuilder&lt;bool&gt;(
        future: darkMode(),
        builder: (context, _snapshot) {
          return Transform.scale(
            scale: 1.5,
            child: Switch(
              value: _snapshot.data ?? false,
              onChanged: (value) {
                save(value);
                setState(() {
  
                });
              },
              activeColor: CustomColors().duskBlue,
              activeTrackColor: CustomColors().noroGrey,
              inactiveThumbColor: CustomColors().lureGrey,
              inactiveTrackColor: CustomColors().noroGrey,
            ),
          );
        },
      );
    }
  
    void save(bool value) async{
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
      await sharedPreferences.setBool("isDark", value);
    }
  
    void toggleSwitch(bool value) {
      ThemeChanger _themeChanger =
          Provider.of&lt;ThemeChanger&gt;(context, listen: false);
  
      if (switchControl == false) {
        setState(() {
          switchControl = true;
        });
        print('Theme is Dark');
  
        _themeChanger.setTheme(CustomThemes.darkTheme.copyWith(
            textTheme:
                CustomThemes.darkTextTheme(CustomThemes.darkTheme.textTheme)));
      } else {
        setState(() {
          switchControl = false;
        });
        print('Theme is Light');
  
        _themeChanger.setTheme(CustomThemes.lightTheme.copyWith(
            textTheme:
                CustomThemes.lightTextTheme(CustomThemes.lightTheme.textTheme)));
      }
    }
  }
  </code></pre>