title: How to resolve "Only static members can be accessed in initializers" in flutter?
body: <p>I'm developing a flutter app, where I need to scan some barcodes, so, for that, I use a plugin called barcode_scan (<a href="https://pub.dartlang.org/packages/barcode_scan" rel="nofollow noreferrer">https://pub.dartlang.org/packages/barcode_scan</a>).
  So, the problem comes when I try to call a function from a RaisedButton which is stored on a List of Steps, because I need show that button inside Stepper widget, when I call the function for init the barcode scanner on the onPressed, Android studio show this message 'only static members can be accessed in initializers'.</p>
  
  <p>The function for init barcode scanner:</p>
  
  <pre><code>Future scan() async {
  try {
    String barcode = await BarcodeScanner.scan();
    setState(() =&gt; this.barcode = barcode);
  } on PlatformException catch (e) {
    if (e.code == BarcodeScanner.CameraAccessDenied) {
      setState(() {
        this.barcode = 'The user did not grant the camera permission!';
      });
    } else {
      setState(() =&gt; this.barcode = 'Unknown error: $e');
    }
  } on FormatException{
    setState(() =&gt; this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
  } catch (e) {
    setState(() =&gt; this.barcode = 'Unknown error: $e');
  }}
  </code></pre>
  
  <p>And the code for the Step List</p>
  
  <pre><code>List&lt;Step&gt; mySteps = [
  new Step(title: new Text("Scan first"),
      content: new Column(
        children: &lt;Widget&gt;[
          new Text("Code"),
          new Container(
            padding: EdgeInsets.only(top: 20),
            child: new Text("A08B",style: TextStyle(
                fontSize: 30,
                color: Colors.red
            ),
          )
          ,),
          new Container(
            child: new RaisedButton(onPressed: scan ,
            child: new Text("Scan"),),
          )
        ],
      ))];
  </code></pre>
  
  <p>Full dart class:</p>
  
  <pre><code>void main() =&gt; runApp(MaterialApp(
          home: Ubicacion(),
      ));
  
  class Ubicacion extends StatefulWidget {
  @override
  _UbicacionState createState() =&gt; _UbicacionState();}
  class _UbicacionState extends State&lt;Ubicacion&gt; {
  
  String barcode = "";
  Future scan() async {
      try {
          String barcode = await BarcodeScanner.scan();
          setState(() =&gt; this.barcode = barcode);
      } on PlatformException catch (e) {
          if (e.code == BarcodeScanner.CameraAccessDenied) {
              setState(() {
                  this.barcode = 'The user did not grant the camera permission!';
              });
          } else {
              setState(() =&gt; this.barcode = 'Unknown error: $e');
          }
      } on FormatException{
          setState(() =&gt; this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
      } catch (e) {
          setState(() =&gt; this.barcode = 'Unknown error: $e');
      }
  }
  
  
  @override
  Widget build(BuildContext context) {
      return Scaffold(
          appBar: AppBar(
              title: Text('hello'),
          ),
          body: Container(
              padding: EdgeInsets.all(32.0),
              child: Center(
                  child: Column(
                      children: &lt;Widget&gt;[
  
                          new Container(
                              child: new Stepper(steps: mySteps,
                              currentStep: this.pasoActual,
                              onStepContinue: (){
                                  setState(() {
                                      if(pasoActual &lt;mySteps.length -1){
                                          pasoActual++;
                                      }else{
                                          pasoActual = 0;
                                      }
                                  });
                              },
                              onStepCancel: (){
                                  setState(() {
                                      if(pasoActual &gt;0){
                                          pasoActual--;
                                      }else{
                                          pasoActual = 0;
                                      }
                                  });
                              },),
                          )
  
  
                      ],
                  ),
              ),
          ),
      );
  }
  
  int pasoActual = 0;
  List&lt;Step&gt; mySteps = [
      new Step(title: new Text("Escanear palet"),
              content: new Column(
                  children: &lt;Widget&gt;[
                      new Text("Codigo"),
                      new Text("ID",),
                      new Text("PLU"),
                      new Container(
                          padding: EdgeInsets.only(top: 20),
                          child: new Text("A08B",style: TextStyle(
                                  fontSize: 30,
                                  color: Colors.red
                          ),
                          )
                          ,),
                      new Container(
                          child: new RaisedButton(onPressed: null ,
                              child: new Text("Escanear"),),
                      )
                  ],
              ))
  ];
  </code></pre>
  
  <p>}</p>