未定义名称“上下文” [英] Undefined name 'context'

查看:128
本文介绍了未定义名称“上下文”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是flutter的新手,在flutter.io之后,在小部件主题中,我们有警报对话框类小部件,



谢谢。

解决方案

由于定义了此方法,它看起来不是Widget类之外的内容,因此 context 成员不存在。使用时,您需要将一种方法传递给该方法。



将方法更改为此:

  ... 
Future< void> _neverSatisfied(BuildContext context)异步{
...


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.

解决方案

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 {
...

这篇关于未定义名称“上下文”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆