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

迁移新机器后构建Flutter项目遇编译错误求助

解决方案

错误根源分析

编译失败源于两个依赖包与当前Flutter SDK版本不兼容:

  1. win32 2.3.6:该版本引用的Char.UnicodeChar/Char.AsciiChar成员已在新版Flutter对应的Dart FFI层中被移除或重命名
  2. flutter_typeahead 3.2.4:使用了Flutter已废弃并移除的maxLengthEnforced参数,新版TextField/CupertinoTextField不再支持该参数

具体修复步骤

1. 升级或强制指定兼容的win32版本

  • 打开项目根目录的pubspec.yaml,若直接依赖了win32,将版本改为**>=3.0.0**的稳定版;若为间接依赖,添加依赖覆盖:
    dependency_overrides:
      win32: ^5.0.0 # 可替换为当前最新稳定版
    
  • 执行命令更新依赖:
    flutter pub get
    

2. 升级flutter_typeahead到适配新版Flutter的版本

  • 修改pubspec.yaml中的flutter_typeahead依赖为最新稳定版(4.x及以上版本已适配新版Flutter):
    dependencies:
      flutter_typeahead: ^4.8.0 # 可替换为当前最新稳定版
    
  • 执行命令更新依赖:
    flutter pub get
    

3. 彻底清理缓存与构建文件

  • 执行清理命令:
    flutter clean
    
  • 删除项目根目录下的.dart_tool文件夹和pubspec.lock文件
  • 重新拉取依赖并运行项目:
    flutter pub get
    flutter run
    

内容的提问来源于stack exchange,提问作者Wesley DaBes

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 10:05:33