title: How to pass data from child widget to its parent
body: <p>I've the below custom widget that make a <code>Switch</code> and reads its status (true/false)</p>
  
  <p>Then I add this one to my main app widget (parent), how can I make the parent knows the value of the switch!</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  class Switchy extends StatefulWidget{
    Switchy({Key key}) : super(key: key);
  
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; new _SwitchyState();
    }
  
  class _SwitchyState extends State&lt;Switchy&gt; {
    var myvalue = true;
  
    void onchange(bool value) {
      setState(() {
        this.myvalue = value;      // I need the parent to receive this one!
        print('value is: $value');
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return             
        new Card(
        child: new Container(
          child: new Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: &lt;Widget&gt;[
              new Text("Enable/Disable the app in the background",
                textAlign: TextAlign.left,
                textDirection: TextDirection.ltr,),
              new Switch(value: myvalue, onChanged: (bool value) =&gt; onchange(value)),
            ],
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p>In the <code>main.dart</code> (parent) file, I started with this:</p>
  
  <pre><code>import 'widgets.dart';
  import 'package:flutter/material.dart';
  
  void main() =&gt; runApp(new MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
        title: 'Flutter Demo',
        theme: new ThemeData(
          primarySwatch: Colors.deepOrange,
        ),
        home: new MyHomePage(title: 'My App settup'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);
  
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; new _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
  
    Widget e = new Switchy();
    //...
  
  }
  </code></pre>