Flutter运行报错:TextTheme类未定义labelLarge getter
问题原因
你使用的chewie_audio:1.4.0依赖了Flutter SDK中较新的TextTheme.labelLarge属性,但你的本地Flutter版本不支持这个属性——labelLarge是Flutter 3.10+版本引入的Material 3文本样式,旧版SDK没有这个getter,因此触发报错。
解决方案
方案1:升级Flutter SDK
执行命令升级到最新稳定版:
flutter upgrade
升级完成后重新运行项目,SDK会提供labelLarge属性,错误即可解决。
方案2:不升级SDK,适配旧版本Flutter
临时修改依赖包代码
找到报错文件路径:C:/Users/admin/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/chewie_audio-1.4.0/lib/src/material_controls.dart,定位到第82行,将:
final iconColor = Theme.of(context).textTheme.labelLarge!.color;
替换为旧版Flutter支持的文本样式属性,比如:
final iconColor = Theme.of(context).textTheme.labelMedium!.color;
(如果labelMedium也不存在,可以尝试bodyText2或caption,根据你的主题视觉需求调整)
降级chewie_audio版本
在项目的pubspec.yaml中,指定一个兼容当前Flutter版本的chewie_audio旧版本,比如:
dependencies: chewie_audio: ^1.3.0
然后执行flutter pub get更新依赖。
内容的提问来源于stack exchange,提问作者Lyd Betcric
相关产品推荐
相关产品推荐

