title: How to Set/Update State of StatefulWidget from other StatefulWidget in Flutter?
body: <ol>
  <li>For Example in the below code plus button works and able to update
  the text but the minus button does not.</li>
  <li>But if we press FloatingActionButton then the State is refreshed .</li>
  <li>The minus button is changing the value of the variable but not
  updating the state of parent widget .</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/7SWW2m.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7SWW2m.png" alt="enter image description here"></a> </p>
  
  <p>here is code .....</p>
  
  <pre><code>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.blue,
        ),
        home: new MyHomePage(title: 'Flutter Demo Home Page'),
      );
    }
  }
  
  int number;
  
  EdgeInsets globalMargin = const EdgeInsets.symmetric(horizontal: 20.0, vertical: 20.0);
  TextStyle textStyle = const TextStyle(
    fontSize: 100.0,
    color: Colors.black,
  );
  
  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; {
    @override
    void initState() {
      super.initState();
      number = number ?? 0;
    }
  
    @override
    Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(
          title: new Text(widget.title),
        ),
        body: new Column(
          children: &lt;Widget&gt;[
            new Text(
              number.toString(),
              style: textStyle,
            ),
            new GridView.count(
              crossAxisCount: 2,
              shrinkWrap: true,
              scrollDirection: Axis.vertical,
              children: &lt;Widget&gt;[
                new InkResponse(
                  child: new Container(
                      margin: globalMargin,
                      color: Colors.green,
                      child: new Center(
                        child: new Text(
                          "+",
                          style: textStyle,
                        ),
                      )),
                  onTap: () {
                    setState(() {
                      number = number + 1;
                    });
                  },
                ),
                new Sub(),
              ],
            ),
          ],
        ),
        floatingActionButton: new FloatingActionButton(
          onPressed: () {
            setState(() {});
          },
          child: new Icon(Icons.update),
        ),
      );
    }
  }
  
  class Sub extends StatefulWidget {
    @override
    _SubState createState() =&gt; new _SubState();
  }
  
  class _SubState extends State&lt;Sub&gt; {
    @override
    Widget build(BuildContext context) {
      return new InkResponse(
        child: new Container(
            margin: globalMargin,
            color: Colors.red,
            child: new Center(
              child: new Text(
                "-",
                style: textStyle,
              ),
            )),
        onTap: () {
          setState(() {
            number = number - 1;
          });
        },
      );
    }
  }
  </code></pre>