How to resolve “Only static members can be accessed in initializers” in flutter?

后端 未结 1 764
不思量自难忘°
不思量自难忘° 2021-01-21 00:07

I\'m developing a flutter app, where I need to scan some barcodes, so, for that, I use a plugin called barcode_scan (https://pub.dartlang.org/packages/barcode_scan). So, the pro

相关标签:
1条回答
  • 2021-01-21 00:40

    The above error occurs when you try to initialize a non-static variable directly when declaring it inside a class. In your case I assume it's the mySteps list which you are initializing directly.

    Try initializing it inside your initState() method if you are using a Stateful Widgetor inside a class constructor and the error will go away.

    You can also check this answer for a detailed explanation regarding the same issue.

    0 讨论(0)
提交回复
热议问题