title: Setstate for statless widget dropdownButton from a stateful parent
body: <p>I have three widgets first one is <code>LightBulb(stateless)</code> that have some color properties. The second one is widget named as <code>LightColorSelector(stateless)</code> that has a <code>DropdownMenu</code> with string type items <code>Red</code>, <code>Green</code>and <code>Blue</code>. And, the third class is <code>Classroom(stateful widget)</code> which is the parent of that two classes. My aim is to set the states from that class.
  I need to set a list of that three colors inside the <code>Classroom</code>, when someone clicks on one of the <code>LightColorSelector</code> items the <code>LightBulb</code> should switches according to clicked color. However, the color inside the  <code>LightBulb</code> returns always null. I think it didn't set. Actually, I might know where is the mistake. I think in the <code>LightColorSelector</code> function there is a <code>onChanged</code> property and I didn't set the <code>value</code> into the <code>func()</code>. I marked below where I suspect the mnistake is occur.</p>
  <pre><code>import 'package:flutter/material.dart';
  
  // ignore: must_be_immutable
  class LightBulb extends StatelessWidget {
    bool isLit;
    Color color;
    LightBulb(bool isLit, Color color) {
      this.isLit = isLit;
      this.color = color;
      print(color.toString());
    }
  
    Widget build(BuildContext context) {
      return Container(
        color: isLit ? color : Colors.red,
        padding: EdgeInsets.all(5),
        child: isLit ? Text('ON') : Text('OFF'),
      );
    }
  }
  
  class LightButton extends StatelessWidget {
    Function func;
    bool isLightOn;
    LightButton(Function func, bool iSLightOn) {
      this.func = func;
      this.isLightOn = iSLightOn;
    }
    String title() {
      if (isLightOn) return &quot;Turn light off&quot;;
      return &quot;Turn light on&quot;;
    }
  
    @override
    Widget build(BuildContext context) {
      return Container(
        padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
        color: Colors.red,
        child: Container(
          color: Colors.blue,
          child: MaterialButton(
            textColor: Colors.white,
            onPressed: () =&gt; func(),
            child: Text(
              title(),
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
      );
    }
  }
  
  class Classroom extends StatefulWidget {
    @override
    _ClassroomState createState() =&gt; _ClassroomState();
  }
  
  class _ClassroomState extends State&lt;Classroom&gt; {
    bool isLightOn = false;
    String title = &quot;Not set yet&quot;;
    List&lt;Color&gt; lightColor = [Colors.red, Colors.green, Colors.blue];
    Color color;
    String value;
    selectLightColor() {
      setState(() {
        if (value == 'Red') color = lightColor[0];
        if (value == 'Green') color = lightColor[1];
        if (value == 'Blue')
          color = lightColor[2];
        else
          color = Colors.amber;
      });
    }
  
    onButtonPressed() {
      setState(() {
        isLightOn = !isLightOn;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Center(
        child: Container(
          color: Colors.blue,
          padding: EdgeInsets.all(5),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              LightBulb(isLightOn, color),
              LightButton(onButtonPressed, isLightOn),
              LightColorSelector(selectLightColor),
            ],
          ),
        ),
      );
    }
  }
  
  class LightColorSelector extends StatelessWidget {
    String initialVal = 'Red';
    Function func;
    LightColorSelector(Function func) {
      this.func = func;
    }
  
    @override
    Widget build(BuildContext context) {
      return Container(
          padding: EdgeInsets.all(10),
          child: DropdownButton(
            value: initialVal,
            onChanged: (value) =&gt; func, // =========== Here the error occurs ==========================
            items: &lt;String&gt;['Red', 'Green', 'Blue']
                .map&lt;DropdownMenuItem&lt;String&gt;&gt;((String value) {
              return DropdownMenuItem&lt;String&gt;(
                value: value,
                child: Text(value),
              );
            }).toList(),
          ));
    }
  }
  
  </code></pre>
  <p>Sample output,</p>
  <p><a href="https://i.stack.imgur.com/LPI5o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LPI5o.png" alt="Output" /></a></p>