Flutter The Function Color isn't defined or Undefined class Color

こ雲淡風輕ζ 提交于 2021-02-17 03:34:39

问题


Okay I don't even know what to write. Everything was working fine few hours ago. Then I saw Flutter upgrade is available. So I tried to upgrade. That's when everything started to fall apart. Anyway, I used vpn to run terminal commands. I was successful. After that every single flutter project I am opening is showing this error. I tried with other projects.

I can run and build apk but this errors are there. Here is output of run command:

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.

Here is Dart Analysis:

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)

BTW My Imports are just fine. Output of 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>

Output of 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!

Output of Packages Get:

C:\src\flutter\bin\flutter.bat --no-color packages get
Running "flutter pub get" in App...                                 1.6s
Process finished with exit code 0

Output of Packages Upgrade:

C:\src\flutter\bin\flutter.bat --no-color packages upgrade
Running "flutter pub upgrade" in App...                            13.3s
Process finished with exit code 0

Things I tried:

  1. Re-installed Flutter, Dart and Android Stuido (Path var checked)
  2. Tried with Intellij & VS Code, Same result.
  3. Restarted Dart Analysis Server
  4. Tried Flutter Clean
  5. Deleted the whole project and went back to old commits to see if something was wrong with the code.

UPDATE: Got some errors:

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').

回答1:


Removing dart:html resolved some errors. But I figured out the issue. The whole flutter dart environment was corrupted. With this server issue, while running upgrade the files got corrupted. As a result I was getting those errors. After completely uninstalling everything and then installing again resolved it. Thanks everyone




回答2:


Try removing import 'dart:html'; in your initialize.dart



来源:https://stackoverflow.com/questions/60918872/flutter-the-function-color-isnt-defined-or-undefined-class-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!