You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

首次运行Flutter应用遇红屏错误,终端报U+0000控制字符异常

解决 Flutter 运行时出现 U+0000 控制字符错误

问题现象

运行首个Flutter应用时出现红屏,终端输出大量如下错误信息:

/C:/src/flutter/flutter/packages/flutter/lib/src/services/asset_bundle.dart: Error: The control character U+0000 can only be used in strings and comments.
/C:/src/flutter/flutter/packages/flutter/lib/src/services/asset_manifest.dart: Error: The control character U+0000 can only be used in strings and comments.
/C:/src/flutter/flutter/packages/flutter/lib/src/services/autofill.dart: Error: The control character U+0000 can only be used in strings and comments.
/C:/src/flutter/flutter/packages/flutter/lib/src/services/binding.dart: Error: The control character U+0000 can only be used in strings and comments.
/C:/src/flutter/flutter/packages/flutter/lib/src/services/debug.dart: Error: The control character U+0000 can only be used in strings and comments.
/C:/src/flutter/flutter/packages/flutter/lib/src/services/hardware_keyboard.dart: Error: The control character U+0000 can only be used in strings and comments.
还有很多类似的错误信息

环境信息

执行flutter doctor -v输出:

C:\src\flutter\flutter\bin>flutter doctor -v
[√] Flutter (Channel stable, 3.16.2, on Microsoft Windows [Version 10.0.19045.3636], locale en-IN)
    • Flutter version 3.16.2 on channel stable at C:\src\flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9e1c857886 (2 days ago), 2023-11-30 11:51:18 -0600
    • Engine revision cf7a9d0800
    • Dart version 3.2.2
    • DevTools version 2.28.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\PNT\AppData\Local\Android\sdk
    • Platform android-33-ext5, build-tools 33.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[√] VS Code (version 1.77.3)
    • VS Code at C:\Users\PNT\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (4 available)
    • IV2201 (mobile)   • 4PLJOFSGBEE6V4CI • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows          • windows-x64    • Microsoft Windows [Version 10.0.19045.3636]
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 119.0.6045.200
    • Edge (web)        • edge             • web-javascript • Microsoft Edge 117.0.2045.60

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

解决方案

1. 修复或重新安装 Flutter SDK

错误指向Flutter框架核心文件中出现无效控制字符,大概率是SDK下载/解压过程中文件损坏:

  • 删除当前Flutter SDK目录(C:\src\flutter\flutter)
  • 重新下载稳定版Flutter SDK,解压至原路径
  • 执行flutter doctor确认SDK完整性

2. 处理Android许可证问题

虽然这不是直接导致红屏的原因,但解决它能避免后续编译问题:

  • 打开命令提示符,运行flutter doctor --android-licenses
  • 按提示输入y同意所有许可证协议

3. 清理项目缓存并重新构建

  • 进入你的Flutter项目目录
  • 执行flutter clean清理旧的构建缓存
  • 执行flutter pub get重新获取所有依赖
  • 最后运行flutter run启动应用

内容的提问来源于stack exchange,提问作者suman singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 19:44:54