title: How to declare a variable inside onPressed Flutter?
body: <p>I am trying to create a variable in <code>onPressed</code>. But it says error: <code>expected {</code>. Can someone show an example of onPressed where a variable is initialized, declared and used?</p>
  <p>Here is my code:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  
  class TestingWidget extends StatefulWidget {
    @override
    _TestingWidgetState createState() =&gt; _TestingWidgetState();
  }
  var requestbody = {
    &quot;apiKey&quot;:&quot;z_P!EJ?dsverbtbspV3K4GxaET&quot;,
    &quot;operationType&quot;:&quot;register_user_otp&quot;,
    &quot;operationData&quot;: {
      &quot;email&quot;: &quot;shewfwrvam@fvbtrg.com&quot;,
      &quot;userName&quot;:&quot;dvre&quot;,
      &quot;accessKey&quot;:&quot;2defr&quot;,
      &quot;accessValue&quot;:&quot;32rfg43v5&quot;,
      &quot;registrationTimeStamp&quot;: 1616919213853
    }
  };
  var url = Uri.parse('https://script.google.com/macros/s/AKfycbz7kTROol8u509M_p9pMZ9XRnL-myVjcRQKeb9Etp_OIMPnH640vHf_0Jp2dvRIco7kOg/exec');
  
  
  class _TestingWidgetState extends State&lt;TestingWidget&gt; {
    @override
    Widget build(BuildContext context) {
      return ElevatedButton(
        onPressed: () =&gt; {
          var response = await http.post(url, body: requestbody);
          print('Response status: ${response.statusCode}');
          print('Response body: ${response.body}');
        },
        child: new Text('Click me'),
      );
    }
  }
  </code></pre>