title: Passing data from another class to another's class onPressed Flutter
body: <p>I'm trying to pass a data from class A to another class B. Class B would accept it and pass the data to Screen C through onPressed(in class B).</p>
  <p>Below is how I pass and retrieve the data. Currently, my output in Screen C is 'null', it should display the data from class A</p>
  <ul>
  <li>Passing data from class A</li>
  </ul>
  <pre><code>class SelectAccount extends StatefulWidget {
    @override
    _SelectAccountState createState() =&gt; _SelectAccountState();
  }
  
  class _SelectAccountState extends State&lt;SelectAccount&gt; {
  
    var dropdownValue = 'one';
  
    @override
    Widget build(BuildContext context) {
      return Container(
        child: Padding(
          padding: EdgeInsets.only(right: 10, left: 10),
          child: Container(
            constraints: BoxConstraints.expand(width: 375.0, height: 100.0),
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(color: Colors.grey),
              borderRadius: BorderRadius.circular(5.0),
            ),
            child: Container(
              child: Padding(
                padding: const EdgeInsets.only(
                    right: 12.0, left: 12.0, top: 5.0, bottom: 5.0),
                child: DropdownButtonHideUnderline(
                  child: DropdownButton&lt;String&gt;(
                    itemHeight: 120,
                    isExpanded: true,
                    value: dropdownValue,
                    onChanged: (String value) {
                      setState(() {
                        dropdownValue = value;
                      });
                    },
                    items: [
                      DropdownMenuItem&lt;String&gt;(
                        child: Column(
                          children: &lt;Widget&gt;[
                            Card(
                              //margin: EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0),
                              child: Container(
                                padding: EdgeInsets.only(left: 10.0),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: &lt;Widget&gt;[
                                    Text(
                                      'Saving Account',
                                      style: TextStyle(
                                        fontSize: 15.0,
                                        fontWeight: FontWeight.bold,
                                        color: Colors.black,
                                      ),
                                    ),
                                    SizedBox(
                                      height: 5.0,
                                    ),
                                    Text(
                                      'Savings XXX-X-XX563-9',
                                      style: TextStyle(
                                        fontSize: 10.0,
                                        color: Colors.grey[900],
                                      ),
                                    ),
                                    SizedBox(
                                      height: 15.0,
                                    ),
                                    Container(
                                      child: Row(
                                        children: &lt;Widget&gt;[
                                          RichText(
                                            text: TextSpan(
                                              text: '56,302.56',
                                              style: TextStyle(
                                                fontSize: 25.0,
                                                fontWeight: FontWeight.bold,
                                                color: Colors.black,
                                              ),
                                              children: &lt;TextSpan&gt;[
                                                TextSpan(
                                                  text: ' THB',
                                                  style: TextStyle(
                                                      fontSize: 15.0,
                                                      fontWeight:
                                                      FontWeight.bold),
                                                ),
                                              ],
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                        value: 'one',
                      ),
                      DropdownMenuItem&lt;String&gt;(
                        child: Column(
                          children: &lt;Widget&gt;[
                            Card(
                              //margin: EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0),
                              child: Container(
                                padding: EdgeInsets.only(left: 10.0),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: &lt;Widget&gt;[
                                    Text(
                                      'Saving Account 2',
                                      style: TextStyle(
                                        fontSize: 15.0,
                                        fontWeight: FontWeight.bold,
                                        color: Colors.black,
                                      ),
                                    ),
                                    SizedBox(
                                      height: 5.0,
                                    ),
                                    Text(
                                      'Savings XXX-X-XX563-9',
                                      style: TextStyle(
                                        fontSize: 10.0,
                                        color: Colors.grey[900],
                                      ),
                                    ),
                                    SizedBox(
                                      height: 15.0,
                                    ),
                                    Container(
                                      child: Row(
                                        children: &lt;Widget&gt;[
                                          RichText(
                                            text: TextSpan(
                                              text: '89,302.56',
                                              style: TextStyle(
                                                fontSize: 25.0,
                                                fontWeight: FontWeight.bold,
                                                color: Colors.black,
                                              ),
                                              children: &lt;TextSpan&gt;[
                                                TextSpan(
                                                  text: ' THB',
                                                  style: TextStyle(
                                                      fontSize: 15.0,
                                                      fontWeight:
                                                      FontWeight.bold),
                                                ),
                                              ],
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                        value: 'two',
                      ),
                      //DropdownMenuItem&lt;String&gt;(),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    }
  }
  
  class PassAccount {
  
    static String dropdownValue;
  
  }
  </code></pre>
  <ul>
  <li>Accepting data in class B</li>
  </ul>
  <pre><code>class ToContainer extends StatefulWidget {
    
    final PassAccount dropdownValue;
  
    ToContainer({Key key, this.dropdownValue}) : super(key: key);
  
    @override
    _ToContainerState createState() =&gt; _ToContainerState();
  }
  </code></pre>
  <ul>
  <li>Passing the accepted data from class B through onPressed() to Screen C</li>
  </ul>
  <pre><code>class _ToContainerState extends State&lt;ToContainer&gt; {
  
    var AccountSelected = PassAccount.dropdownValue;
  
    @override
    Widget build(BuildContext context) {
      return Container(
        color: Colors.white,
        child: Column(
          children: &lt;Widget&gt;[
            Container(
              padding: EdgeInsets.only(
                  top: 5.0, left: 10.0, right: 10.0, bottom: 10.0),
              child: SafeArea(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: &lt;Widget&gt;[
                    Row(
                      children: &lt;Widget&gt;[
                        Expanded(
                          child: CupertinoButton(
                            child: Text(
                              'Next',
                              style: style.clickButton,
                            ),
                            onPressed: () {
                              var route = new MaterialPageRoute(
                                builder: (BuildContext context) =&gt;
                                    new DirectedScreen(
                                        value: PassData(
                                  account: AccountSelected,
                                )),
                              );
                              Navigator.of(context).push(route);
                            },
                            color: Colors.blue[600],
                            borderRadius: BorderRadius.circular(200.0),
                            disabledColor: Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      );
    }
  }
  
  
  
  class PassData {
  
    final String account;
  
    const PassData(
        {
          this.account}
        );
  }
  </code></pre>
  <ul>
  <li>Display data in Screen C</li>
  </ul>
  <pre><code>class DirectedScreen extends StatefulWidget {
    final PassData value;
  
    DirectedScreen({Key key, this.value}) : super(key: key);
  
    @override
    _DirectedScreenState createState() =&gt; _DirectedScreenState();
  }
  
  class _DirectedScreenState extends State&lt;DirectedScreen&gt; {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: Text('Transfer Summary'),
        ),
        body: Container(
          child: new Center(
            child: Column(
              children: &lt;Widget&gt;[
                Padding(
                  child: new Text(
                    'PASSED VALUES',
                    style: new TextStyle(
                        fontWeight: FontWeight.bold, fontSize: 20.0),
                    textAlign: TextAlign.center,
                  ),
                  padding: EdgeInsets.only(bottom: 20.0),
                ),
                Padding(
                  child: new Text(
                    'Bank : ${widget.value.account}',
                    style: new TextStyle(fontWeight: FontWeight.bold),
                    textAlign: TextAlign.left,
                  ),
                  padding: EdgeInsets.all(10.0),
                ),
              ],
            ),
          ),
        ),
      );
    }
  }
  
  </code></pre>
  <p>Thank you in advanced for the help !</p>