【问题标题】:Undefined name 'context'未定义的名称“上下文”
【发布时间】:2019-07-07 06:05:11
【问题描述】:

我是 Flutter 的新手,在 Flutter.io 之后,在小部件主题中,我们有 Alert Dialog 类小部件,https://docs.flutter.io/flutter/material/AlertDialog-class.html

我们有一些示例代码,其中包含以下错误。任何人都可以帮助解决它们。

谢谢。

【问题讨论】:

    标签: dart visual-studio-code flutter


    【解决方案1】:

    因为这个方法是定义在 Widget 类之外的,所以 Widget 类的 context 成员不存在。使用时需要传入这个方法。

    将您的方法更改为:

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

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 2021-11-06
      • 1970-01-01
      • 2021-03-24
      • 2020-01-28
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      相关资源
      最近更新 更多