title: Flutter : Trying pass a variable to next screen based on DropDownButton input
body: <p>I am trying to reduce a products(smartphone) price based on   user dropdown  input &amp; pass the price to next screen. My code has no error &amp; runs perfectly but the problem is, it reduces price based on only one switch statement (the initial one selected globally for dropdown value) because <code>setState</code> method is working only on changing dropdown value displayed on screen, not in the switch statement containing function.  Can someone help me on how to solve this. I tried many things, but nothing helped. Below is my code (It's long, so I  skipped widget building parts &amp; designing parts here).</p>
  <p>Value has been defined like this</p>
  <pre class="lang-dart prettyprint-override"><code>   double price = 18000;  
     String bdropDownValue = 'Less than 6 hours'; //initialvalue
      final List&lt;String&gt; bItems = [
      'Less than 6 hours',
      'Less than 12 hours',
      'Less than 24 hours'],
  
  </code></pre>
  <p><strong>DropdownButtonFormField</strong></p>
  <pre class="lang-dart prettyprint-override"><code>
  DropdownButtonFormField(value: bdropDownValue,
                          items: bItems.map((bItems) {
                            return DropdownMenuItem(
                              value: bItems,
                              child: Text(bItems),
                            );
                          }).toList(),
                          onChanged: (String? value) {
                            setState(() {
                              bdropDownValue = value!;
                            });
                          },
                          ),
                    /// button used to calculate next
                     TextButton(
                            onPressed: () {
                              calculator(bdropDownValue);
                            },
                            child: Text(
                              &quot;confirm&quot;,
                              ),
  </code></pre>
  <p>I am using this method to calculate</p>
  <pre class="lang-dart prettyprint-override"><code>void calculator(String bdropDownValue) {
      switch (bdropDownValue) {
        case 'Less than 6 hours':
          price = price - 3000;
          break;
        case 'Less than 12 hours':
          price = price - 1500;
          break;
        case 'Less than 24 hours':
          price = price - 1000;
          break;
      }
  </code></pre>
  <p>And using <code>Navigator</code> like this inside calculator method</p>
  <pre class="lang-dart prettyprint-override"><code>Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) =&gt; priceScreen(
                    price: price,
                  )));
    }
  }
  </code></pre>