title: Is it possible to change the state of another class using a button which is located at somewhere else in the widget tree
body: <p>This is my widget tree. I want to change the Text widget in the <code>MemberSection</code> class when I press <code>RaisedButton</code> in the <code>AdminSection</code> class. <strong>Both <code>MemberSection</code> and <code>AdminSection</code> are in <code>HomePage</code> class.</strong></p>
  
  <p><a href="https://i.stack.imgur.com/DFoHp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DFoHp.jpg" alt="enter image description here"></a></p>
  
  <p>Below are dart files:</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  void main() {
    runApp(
      MaterialApp(
        home: HomePage(),
      ),
    );
  }
  
  class HomePage extends StatelessWidget {
    final int count = 0;
  
    @override
    Widget build(BuildContext context) {
      return new Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: &lt;Widget&gt;[MemberSection(count), AdminSection(count)],
        ),
      );
    }
  }
  
  class MemberSection extends StatefulWidget {
    MemberSection(this.count);
  
    final int count;
  
    @override
    _MemberSectionState createState() =&gt; new _MemberSectionState();
  }
  
  class _MemberSectionState extends State&lt;MemberSection&gt; {
    @override
    Widget build(BuildContext context) {
      return new Text('${widget.count} member(s)');//I need to change this widget
    }
  }
  
  class AdminSection extends StatefulWidget {
    AdminSection(this.count);
  
    final int count;
  
    @override
    _AdminSectionState createState() =&gt; new _AdminSectionState();
  }
  
  class _AdminSectionState extends State&lt;AdminSection&gt; {
    void incrementer() {
      setState(() {
        //widget.count++; //cannt do
      });
    }
  
    void decrementer() {
      setState(() {
        //widget.count--; //cannt do
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return new Column(
        children: &lt;Widget&gt;[
          Text('${widget.count} admin(s)'),//Also, I need to change this widget
          ButtonBar(
            children: &lt;Widget&gt;[
              RaisedButton(
                child: Text('add a member'),
                onPressed: incrementer,
              ),
              RaisedButton(
                child: Text('delete a member'),
                onPressed: decrementer,
              ),
            ],
          ),
        ],
      );
    }
  }
  </code></pre>
  
  <p>Note: this example for to demonstrate my problem.</p>
  
  <p>I know that I can implement <code>incrementer</code> and <code>decrementer</code> in <code>HomePage</code> class and pass the function down the widget but according to this scenario it cannot be done, because one <code>RaisedButton</code> widgets are in other side of the widget tree.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Linked duplicate question is different from my question because, I'm not instantiating the <code>MemberSection</code> inside <code>AdminSection</code></p>