【问题标题】:In Flutter the VS Code editor throws an error - The function 'myApp' isn't defined在 Flutter 中,VS 代码编辑器抛出错误 - 未定义函数“myApp”
【发布时间】:2020-05-27 19:02:03
【问题描述】:

我是颤振和飞镖的初学者,我刚刚创建了我的应用程序,因为它会自动创建一个模板应用程序,它会在测试文件夹中的 widget_test.dart 文件中引发错误

The function 'myApp' isn't defined.
Try importing the library that defines 'myApp', correcting the name to the name of an existing function, or defining a function named 'myApp'.
{
    "resource": "/D:/development/hello_rectangle/test/widget_test.dart",
    "owner": "dart",
    "code": "undefined_function",
    "severity": 8,
    "message": "The function 'myApp' isn't defined.\nTry importing the library that defines 'myApp', correcting the name to the name of an existing function, or defining a function named 'myApp'.",
    "source": "dart",
    "startLineNumber": 16,
    "startColumn": 29,
    "endLineNumber": 16,
    "endColumn": 34,
    "tags": []
}

我试过升级flutter,但是不行!!

【问题讨论】:

  • 你有没有按照安装和设置flutter一步一步来?
  • 是的,我做到了。我最近为了练习目的运行了几个应用程序,我不知道这个错误是如何在这个默认模板代码中引起的!!

标签: android-studio flutter dart visual-studio-code


【解决方案1】:

每当您创建一个新项目时,main.dart 文件中都会提供预先编写的代码,这有助于新用户测试他们不理解的代码,但是当我们想从头开始创建一些东西时,@987654322 @ 定义在位于 Project 下的测试文件中,只需点击 Project 附近的向下箭头,您将看到测试文件,打开并删除 widget_test.dart file

删除widget_test.dart file后,错误消失。

【讨论】:

    【解决方案2】:

    您可能正在为应用程序运行测试

    您可以更改默认应用程序的代码,它开始报错。

    您可以简单地删除该文件以避免测试应用程序,或者您可以为应用程序创建测试。

    要了解更多关于 Flutter 测试的信息,请点击:https://flutter.dev/docs/testing

    【讨论】:

    • 您好,谢谢。我删除了测试文件,错误消失了,但是删除那个测试文件后会有什么问题吗?
    • 测试文件用于开发应用程序的测试用例,当您开发任何应用程序并希望以编程方式进行测试时,您可以使用它。如果您不想以这种方式进行测试,那么它不会以任何方式影响您的应用程序。
    • 感谢您的支持,有没有介绍widget_test.dart文件概念的视频教程?
    • youtube.com/watch?v=75i5VmTI6A0&t=134s 这个教程很不错,但是如果你是 Flutter 新手,那么我认为你可以避免在开始时进行测试。祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 2018-12-20
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多