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

Flutter 3.22.3运行报错:TextTheme无button getter定义

解决方案

问题根源

Flutter 3.16及后续版本中,TextTheme的button getter已被废弃移除,官方替代为labelLarge。你使用的pin_code_fields-7.4.0版本依赖旧API,和Flutter 3.22.3不兼容,这是报错的核心原因。

具体解决步骤

  • 升级pin_code_fields到兼容版本
    打开项目的pubspec.yaml,将pin_code_fields的版本更新为适配Flutter 3.22的版本(比如^8.0.1),然后执行命令:

    flutter pub get
    

    新版本的包已经修复了TextTheme API的兼容性问题。

  • 临时修复:手动修改包源码(不推荐长期使用)
    如果暂时无法升级包,可找到本地依赖中的pin_code_fields.dart文件(路径通常为./.pub-cache/hosted/pub.dev/pin_code_fields-7.4.0/lib/pin_code_fields.dart),把所有用到TextTheme.button的地方替换成TextTheme.labelLarge,保存后重新运行项目。

  • 确认device_info_plus升级完成
    尽管device_info_plus 8.0.0已停止维护,但升级到10.1.1是正确操作。确认pubspec.yaml中已更新版本,再执行flutter pub get,避免潜在依赖冲突影响项目构建。

内容的提问来源于stack exchange,提问作者Muhammad Aiman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 04:44:51