Undefined name 'context'

2019-08-10 20:49发布

问题:

I am new to flutter, following the flutter.io and in widgets topic we have the Alert Dialog class widget, https://docs.flutter.io/flutter/material/AlertDialog-class.html

There we have some sample code and getting the below errors in it. Can anyone help in solving them.

Thanks.

回答1:

Because this method is defined what looks to be outside of a Widget class, the context member of a Widget class doesn't exist. You need to pass one into this method when you use.

Changed your method to this:

...
Future<void> _neverSatisfied(BuildContext context) async {
...