flutter - Flutter函数颜色未定义或未定义类颜色

标签 flutter dart

好吧,我什至不知道该写些什么。几个小时前一切正常。然后我看到Flutter升级可用。所以我尝试升级。那就是一切开始崩溃的时候。无论如何,我使用vpn运行终端命令。我成功了之后,我打开的每个 flutter 项目都显示此错误。
我尝试了其他项目。

我可以运行并构建apk,但是存在此错误。 这是运行命令的输出:

Launching lib\main.dart on POCOPHONE F1 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
D/FlutterActivity(27090): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(27090): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(27090): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(27090): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(27090): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@4b90e47
D/FlutterActivityAndFragmentDelegate(27090): Executing Dart entrypoint: main, and sending initial route: /
Debug service listening on ws://127.0.0.1:51142/_qlZxn05Q8o=/ws
Syncing files to device POCOPHONE F1...
W/.covidtrackerb(27090): Long monitor contention with owner Answers Events Handler1 (27294) at int java.lang.String.indexOf(java.lang.String, java.lang.String, int)(String.java:1742) waiters=0 in io.fabric.sdk.android.services.common.AdvertisingInfo io.fabric.sdk.android.services.common.IdManager.getAdvertisingInfo() for 1.302s
W/.covidtrackerb(27090): Long monitor contention with owner Answers Events Handler1 (27294) at int java.lang.String.indexOf(java.lang.String, java.lang.String, int)(String.java:1742) waiters=1 in io.fabric.sdk.android.services.common.AdvertisingInfo io.fabric.sdk.android.services.common.IdManager.getAdvertisingInfo() for 1.300s
D/NetworkSecurityConfig(27090): No Network Security Config specified, using platform default
E/FirebaseInstanceId(27090): binding to the service failed
E/AccessibilityBridge(27090): VirtualView node must not be the root node.
I/.covidtrackerb(27090): ProcessProfilingInfo new_methods=3224 is saved saved_to_disk=1 resolve_classes_delay=8000
E/AccessibilityBridge(27090): VirtualView node must not be the root node.
I/flutter (27090): ::Data connection is available.
E/AccessibilityBridge(27090): VirtualView node must not be the root node.
I/flutter (27090): Instance of 'Future<Response>'
I/flutter (27090): Instance of 'Future<Response>'
I/flutter (27090): size response :2
I/flutter (27090): [Instance of 'Response', Instance of 'Response']
I/flutter (27090): CovidBdState Instance of 'AllData'
E/AccessibilityBridge(27090): VirtualView node must not be the root node.

这是Dart分析:
error: Undefined name 'Brightness'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:45)
error: The method 'Color' isn't defined for the class '_HomePageState'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:53)
error: The method 'Color' isn't defined for the class '_HomePageState'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:58)
error: The method 'Color' isn't defined for the class '_HomePageState'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:74)
error: The method 'Color' isn't defined for the class '_HomePageState'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:104)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:106)
error: The method 'Color' isn't defined for the class '_HomePageState'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:113)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:115)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:128)
error: The method 'Color' isn't defined for the class '_HomePageState'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:136)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:213)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:260)
error: The method 'Color' isn't defined for the class 'todo'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:409)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:419)
error: The method 'Color' isn't defined for the class 'HeatMapTile'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:435)
error: The method 'Color' isn't defined for the class 'HeatMapTile'. (undefined_method at [covidtrackerbd] lib\main_screen.dart:455)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:537)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\main_screen.dart:547)
error: The method 'Color' isn't defined for the class 'LoadingScreen'. (undefined_method at [covidtrackerbd] lib\screens\loadingScreen.dart:15)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\screens\loadingScreen.dart:41)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\screens\loadingScreen.dart:52)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\loadingScreen.dart:65)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\doctors_report.dart:64)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\doctors_report.dart:68)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\doctors_report.dart:131)
error: Undefined name 'TextDecoration'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\doctors_report.dart:547)
error: Undefined name 'TextDecoration'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\doctors_report.dart:555)
error: Undefined name 'Brightness'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\formSubmissionPage.dart:24)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\formSubmissionPage.dart:81)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\formSubmissionPage.dart:85)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\formSubmissionPage.dart:95)
error: Undefined name 'TextDecoration'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\formSubmissionPage.dart:439)
error: Undefined name 'TextDecoration'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\formSubmissionPage.dart:447)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\neighbours_report.dart:58)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\neighbours_report.dart:62)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\neighbours_report.dart:102)
error: Undefined name 'TextDecoration'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\neighbours_report.dart:391)
error: Undefined name 'TextDecoration'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\neighbours_report.dart:398)
error: Undefined name 'Brightness'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\possible_affected.dart:30)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\possible_affected.dart:65)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\possible_affected.dart:85)
error: Undefined name 'Brightness'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\recurringUpdate.dart:15)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\self_reporting_page.dart:74)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\self_reporting_page.dart:94)
error: Undefined name 'Brightness'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\survey_page.dart:19)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\survey_page.dart:43)
error: Undefined name 'FontWeight'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\Report\survey_page.dart:45)
error: The method 'Color' isn't defined for the class '_SurveyPageState'. (undefined_method at [covidtrackerbd] lib\screens\tabs\Report\survey_page.dart:58)
error: The method 'Color' isn't defined for the class '_SurveyPageState'. (undefined_method at [covidtrackerbd] lib\screens\tabs\Report\survey_page.dart:102)
error: Undefined name 'Brightness'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\developerStory.dart:10)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\developerStory.dart:23)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\developerStory.dart:34)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\developerStory.dart:41)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\developerStory.dart:48)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:25)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:25)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:26)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:26)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:27)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:27)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:28)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:28)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:29)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:29)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:30)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:30)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:31)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:31)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:33)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:33)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:34)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:34)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:35)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:35)
error: The function 'Color' isn't defined. (undefined_function at [covidtrackerbd] lib\screens\tabs\home\constants.dart:36)
error: Undefined class 'Color'. (undefined_class at [covidtrackerbd] lib\screens\tabs\home\constants.dart:36)
error: Undefined name 'Brightness'. (undefined_identifier at [covidtrackerbd] lib\screens\tabs\location.dart:34)
error: Undefined name 'TextAlign'. (undefined_identifier at [covidtrackerbd] lib\screens\widgets\snackPage.dart:20)
info: Unused import: 'dart:async'. (unused_import at [covidtrackerbd] lib\main.dart:2)
info: Unused import: 'package:firebase_crashlytics/firebase_crashlytics.dart'. (unused_import at [covidtrackerbd] lib\main.dart:8)
info: Name non-constant identifiers using lowerCamelCase. (non_constant_identifier_names at [covidtrackerbd] lib\main_screen.dart:312)
info: Name types using UpperCamelCase. (camel_case_types at [covidtrackerbd] lib\main_screen.dart:395)
info: This method overrides a method annotated as @mustCallSuper in 'State', but doesn't invoke the overridden method. (must_call_super at [covidtrackerbd] lib\screens\tabs\Report\doctors_report.dart:33)
info: Unused import: 'package:covidtrackerbd/services/authentication.dart'. (unused_import at [covidtrackerbd] lib\screens\tabs\Report\possible_affected.dart:5)
info: Unused import: 'formSubmissionPage.dart'. (unused_import at [covidtrackerbd] lib\screens\tabs\Report\possible_affected.dart:9)
info: Unused import: 'package:covidtrackerbd/services/api.dart'. (unused_import at [covidtrackerbd] lib\screens\tabs\Report\self_reporting_page.dart:3)
info: Unused import: 'package:covidtrackerbd/services/json.dart'. (unused_import at [covidtrackerbd] lib\screens\tabs\Report\self_reporting_page.dart:5)
info: Unused import: 'package:flutter_html/flutter_html.dart'. (unused_import at [covidtrackerbd] lib\screens\tabs\Report\self_reporting_page.dart:8)
info: Unused import: 'package:flutter/cupertino.dart'. (unused_import at [covidtrackerbd] lib\screens\tabs\home\constants.dart:23)
info: This method overrides a method annotated as @mustCallSuper in 'AutomaticKeepAliveClientMixin', but doesn't invoke the overridden method. (must_call_super at [covidtrackerbd] lib\screens\tabs\location.dart:29)

顺便说一句,我的导入还可以。
Flutter Doctor的输出:

Microsoft Windows [Version 10.0.18363.720]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Momshad\Documents\GitHub\COVID-Tracker-BD-master\COVID-Tracker-BD-master\App>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale en-001)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 3.6)
[√] IntelliJ IDEA Community Edition (version 2019.3)
[√] VS Code (version 1.43.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.

C:\Users\Momshad\Documents\GitHub\COVID-Tracker-BD-master\COVID-Tracker-BD-master\App>

Flutter Doctor -v的输出:
C:\Users\Momshad\Documents\GitHub\COVID-Tracker-BD-master\COVID-Tracker-BD-master\App>flutter doctor -v
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale en-001)
    • Flutter version 1.12.13+hotfix.8 at C:\src\flutter
    • Framework revision 0b8abb4724 (7 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Users\Momshad\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] IntelliJ IDEA Community Edition (version 2019.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.3
    • Flutter plugin version 44.0.3
    • Dart plugin version 193.6911.31

[√] VS Code (version 1.43.1)
    • VS Code at C:\Users\Momshad\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.8.1

[√] Connected device (1 available)
    • POCOPHONE F1 • 9ea76ae • android-arm64 • Android 10 (API 29)

• No issues found!

软件包输出获取:
C:\src\flutter\bin\flutter.bat --no-color packages get
Running "flutter pub get" in App...                                 1.6s
Process finished with exit code 0

软件包升级的输出:
C:\src\flutter\bin\flutter.bat --no-color packages upgrade
Running "flutter pub upgrade" in App...                            13.3s
Process finished with exit code 0

我尝试过的事情:
  • 重新安装Flutter,Dart和Android Stuido(检查路径var)
  • 尝试使用Intellij和VS代码,结果相同。
  • 重新启动Dart Analysis Server
  • 尝试 flutter 清洁
  • 删除了整个项目,然后返回到旧的提交,以查看代码是否有问题。

  • 更新:有一些错误:
    Launching lib\main.dart on POCOPHONE F1 in debug mode...
    
    Compiler message:
    lib/initialize.dart:2:8: Error: Not found: 'dart:html'
    import 'dart:html';
           ^
    /C:/src/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+4/lib/src/browser_client.dart:6:8: Error: Not found: 'dart:html'
    import 'dart:html';
           ^
    /C:/src/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+4/lib/src/browser_client.dart:34:18: Error: 'HttpRequest' isn't a type.
      final _xhrs = <HttpRequest>{};
                     ^^^^^^^^^^^
    /C:/src/flutter/packages/flutter/lib/src/painting/_network_image_web.dart:64:12: Error: Method not found: 'webOnlyInstantiateImageCodecFromUrl'.
        return ui.webOnlyInstantiateImageCodecFromUrl(resolved); // ignore: undefined_function
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /C:/src/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+4/lib/src/browser_client.dart:58:34: Error: 'Blob' isn't a type.
          var blob = xhr.response as Blob ?? Blob([]);
                                     ^^^^
    /C:/src/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+4/lib/src/browser_client.dart:46:15: Error: The method 'HttpRequest' isn't defined for the class 'BrowserClient'.
     - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+4/lib/src/browser_client.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'HttpRequest'.
        var xhr = HttpRequest();
                  ^^^^^^^^^^^
    /C:/src/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+4/lib/src/browser_client.dart:58:42: Error: The method 'Blob' isn't defined for the class 'BrowserClient'.
     - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+4/lib/src/browser_client.dart').
    

    最佳答案

    删除dart:html可解决一些错误。但是我发现了问题。整个 Dart 环境都损坏了。遇到此服务器问题,在运行升级时,文件已损坏。结果,我遇到了那些错误。完全卸载所有内容后再重新安装即可解决。感谢大家

    关于flutter - Flutter函数颜色未定义或未定义类颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60918872/

    相关文章:

    dart - 如何从事件e获取元素或元素本身

    dart - 渲染列表项然后滚动到底部

    flutter - 无法在 Macbook air M1 中安装 cocoapods,每次创建 flutter 项目时 pod 文件都丢失

    flutter - FractionallySizedBox 在 Flutter 中具有最大尺寸

    flutter - 如何更改文本字段 flutter 中的值?

    flutter - 如何在 flutter 中返回 <Widget>[ ]?

    android - Flutter:根据设备明暗模式更改应用程序亮度

    android - flutter 如何通过打开对话框打开 txt 文件到特定页面?

    dart - 使用 `$1`的Dart正则表达式

    dart - 如何在 flutter 中制作全屏对话框?