title: How to get a value from a dialog in flutter?
body: <p>I am creating an app and I want to show a dialog for the user which contains a slider to pick a value.</p>
  
  <p>the problem comes here, I want to get the value of that slider which user picked and deal with it.</p>
  
  <p>I am using the dialog as a stateful widget and everything works okay except returning the value as I've mentioned.</p>
  
  <hr>
  
  <h2><strong>The Widget</strong></h2>
  
  <pre class="lang-dart prettyprint-override"><code>class Dialog extends StatefulWidget {
    @override
    _DialogState createState() =&gt; _DialogState();
  
    final double val;
  
    Dialog({this.val,});
  }
  
  class _DialogState extends State&lt;Dialog&gt; {
    double value = 0;
  
    @override
    void initState() {
      super.initState();
      value = widget.val;
    }
    @override
    Widget build(BuildContext context) {
      return AlertDialog(
        title: Slider(
          value: value,
          min: 0,
          max: 100,
          onChanged: (va) {
            setState(() {
              value = va;
            });
          },
        ),
      );
    }
  }
  
  </code></pre>
  
  <p><strong>show dialog code</strong></p>
  
  <pre class="lang-dart prettyprint-override"><code>double vale = 0;
  
  -------
  
  () async {
              await showDialog(
                context: context,
                builder: (context) =&gt; Dialog(
                  val: vale,
                ),
              );
            }
  </code></pre>