title: Flutter - dynamically change container color
body: <p>I have an issue with my flutter application.
  In my drawer I have created a toggle button to switch between light and dark styles.</p>
  <p>Now this works for the most part, however the issue is that it seems that I can not dynamically change the color of drawer container color.</p>
  <p>Can I get some assistance please, this is driving me nuts?</p>
  <p>This code does not work - <code>style: Theme.of(context).CustomColors().fusaBlue,</code></p>
  <pre><code>- theme_switch_widget.dart -
      import 'package:flutter/material.dart';
      
      import 'theme_switch_state.dart';
      
      class ThemeSwitch extends StatefulWidget {
        
        @override
        ThemeSwitchState createState() =&gt; new ThemeSwitchState();
      }
  
      - theme_switch_state.dart -
      import 'package:flutter/material.dart';
      
      import '../../themes/global/themes.dart';
      import 'themes_custom.dart';
      
      class ThemeSwitchState extends State {
        bool switchControl = false;
        //var textHolder = 'Theme is Light';
      
        @override
        Widget build(BuildContext context) {
          return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
            Transform.scale(
                scale: 1.5,
                child: Switch(
                  onChanged: toggleSwitch,
                  value: switchControl,
                  activeColor: CustomColors().skyBlue,
                  activeTrackColor: CustomColors().goreBlue,
                  inactiveThumbColor: CustomColors().loreGrey,
                  inactiveTrackColor: CustomColors().noroGrey,
                )),
            /*Text(
              '$textHolder',
              style: TextStyle(fontSize: 24),
            )*/
          ]);
        }
      
        void _changeTheme(BuildContext buildContext, MyThemeKeys key) {
          CustomTheme.instanceOf(buildContext).changeTheme(key);
        }
      
        void toggleSwitch(bool value) {
          if (switchControl == false) {
            setState(() {
              switchControl = true;
              //textHolder = 'Theme is Dark';
            });
            print('Theme is Dark');
      
            // Put your code here which you want to execute on Switch ON event.
            _changeTheme(context, MyThemeKeys.DARK);
      
          } else {
            setState(() {
              switchControl = false;
              //textHolder = 'Theme is Light';
            });
            print('Theme is Light');
      
            // Put your code here which you want to execute on Switch OFF event.
            _changeTheme(context, MyThemeKeys.LIGHT);
          }
        }
      }
  
      - themes_custom.dart -
  import 'package:flutter/material.dart';
  import 'package:flutter/widgets.dart';
  import './themes.dart';
  
  class _ThemesCustom extends InheritedWidget {
    final CustomThemeState data;
  
    _ThemesCustom({
      this.data,
      Key key,
      @required Widget child,
    }) : super(key: key, child: child);
  
    @override
    bool updateShouldNotify(_ThemesCustom oldWidget) {
      return true;
    }
  }
  
  class CustomTheme extends StatefulWidget {
    final Widget child;
    final MyThemeKeys initialThemeKey;
  
    const CustomTheme({
      Key key,
      this.initialThemeKey,
      @required this.child,
    }) : super(key: key);
  
    @override
    CustomThemeState createState() =&gt; new CustomThemeState();
  
    static ThemeData of(BuildContext context) {
      _ThemesCustom inherited =
          (context.dependOnInheritedWidgetOfExactType&lt;_ThemesCustom&gt;());
      return inherited.data.theme;
    }
  
    static CustomThemeState instanceOf(BuildContext context) {
      _ThemesCustom inherited =
          (context.dependOnInheritedWidgetOfExactType&lt;_ThemesCustom&gt;());
      return inherited.data;
    }
  }
  
  class CustomThemeState extends State&lt;CustomTheme&gt; {
    ThemeData _theme;
  
    ThemeData get theme =&gt; _theme;
  
    @override
    void initState() {
      _theme = MyThemes.getThemeFromKey(widget.initialThemeKey);
      super.initState();
    }
  
    void changeTheme(MyThemeKeys themeKey) {
      setState(() {
        _theme = MyThemes.getThemeFromKey(themeKey);
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return new _ThemesCustom(
        data: this,
        child: widget.child,
      );
    }
  }
  
  - themes.dart -
  import 'package:flutter/material.dart';
  
  enum MyThemeKeys {
    LIGHT,
    DARK,
  }
  
  class CustomColors {
    final novaWhite = Color(0xffecf0f1);
    final loreGrey = Color(0xff6c7a84);
    final noroGrey = Color(0xff424b51);
    final skyBlue = Color(0xff1da1f2);
    final fusaBlue = Color(0xff053959);
    final goreBlue = Color(0xff032234);
    final limeGreen = Color(0xff3bd37b);
    final leafGreen = Color(0xff2ecc71);
    final sageGreen = Color(0xff208c4d);
  }
  
  class MyThemes {
    static TextTheme baseTextTheme(TextTheme base) {
      return base.copyWith(
        display4: base.display4.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.w100,
          fontSize: 112.0,
        ),
        display3: base.display3.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 56.0,
        ),
        display2: base.display2.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 45.0,
        ),
        display1: base.display1.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 34.0,
        ),
        headline: base.headline.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 24.0,
        ),
        title: base.title.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.w500,
          fontSize: 20.0,
        ),
        subhead: base.subhead.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 16.0,
        ),
        body2: base.body2.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.w500,
          fontSize: 14.0,
        ),
        body1: base.body1.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 14.0,
        ),
        caption: base.caption.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 12.0,
        ),
        button: base.button.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.w500,
          fontSize: 14.0,
        ),
        subtitle: base.subtitle.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.w500,
          fontSize: 14.0,
        ),
        overline: base.overline.copyWith(
          fontFamily: 'Iceland',
          fontWeight: FontWeight.normal,
          fontSize: 10.0,
        ),
      );
    }
  
    static final ThemeData lightTheme = ThemeData(
      brightness: Brightness.light,
      primaryColor: CustomColors().limeGreen,
      indicatorColor: CustomColors().loreGrey,
      accentColor: CustomColors().limeGreen,
      scaffoldBackgroundColor: CustomColors().novaWhite,
  
      iconTheme: IconThemeData(
        size: 30.0,
        color: CustomColors().noroGrey,
      ),
      dividerTheme: DividerThemeData(
        thickness: 0.5,
        indent: 16,
        endIndent: 16,
        color: CustomColors().limeGreen,
      ),
      buttonColor: CustomColors().novaWhite,
      backgroundColor: CustomColors().novaWhite,
    );
  
    static final ThemeData darkTheme = ThemeData(
      brightness: Brightness.dark,
      primaryColor: CustomColors().skyBlue,
      indicatorColor: CustomColors().loreGrey,
      accentColor: CustomColors().skyBlue,
      scaffoldBackgroundColor: CustomColors().novaWhite,
      iconTheme: IconThemeData(
        size: 30.0,
        color: CustomColors().noroGrey,
      ),
      dividerTheme: DividerThemeData(
        thickness: 0.5,
        indent: 16,
        endIndent: 16,
        color: CustomColors().skyBlue,
      ),
      buttonColor: CustomColors().novaWhite,
      backgroundColor: CustomColors().novaWhite,
  
    );
  
    static ThemeData getThemeFromKey(MyThemeKeys themeKey) {
      switch (themeKey) {
        case MyThemeKeys.LIGHT:
          return lightTheme.copyWith(
            textTheme: baseTextTheme(lightTheme.textTheme),
          );
          break;
        case MyThemeKeys.DARK:
          return darkTheme.copyWith(
            textTheme: baseTextTheme(darkTheme.textTheme),
          );
          break;
        default:
          return lightTheme.copyWith(
            textTheme: baseTextTheme(lightTheme.textTheme),
          );
          break;
      }
    }
  }
  </code></pre>