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

Flutter项目突发Firebase相关编译错误求助

Flutter项目编译失败:Firebase UI Auth与Dart版本兼容问题

问题现象

原本运行正常的Flutter项目,返回后编译时触发Firebase相关错误,无法进入主函数,核心报错信息如下:

错误日志

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
../../AppData/Local/Pub/Cache/hosted/pub.dev/firebase_ui_auth-1.14.0/lib/src/screens/internal/multi_provider_screen.dart:25:14: Error: A value of type 'List<AuthProvider<AuthListener, AuthCredential>>?' can't be returned from a function with return type 'List<AuthProvider<AuthListener, AuthCredential>>' because 'List<AuthProvider<AuthListener, AuthCredential>>?' is nullable and 'List<AuthProvider<AuthListener, AuthCredential>>' isn't.
 - 'List' is from 'dart:core'.
 - 'AuthProvider' is from 'package:firebase_ui_auth/src/providers/auth_provider.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/firebase_ui_auth-1.14.0/lib/src/providers/auth_provider.dart').
 - 'AuthListener' is from 'package:firebase_ui_auth/src/providers/auth_provider.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/firebase_ui_auth-1.14.0/lib/src/providers/auth_provider.dart').
 - 'AuthCredential' is from 'package:firebase_auth_platform_interface/src/auth_credential.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/firebase_auth_platform_interface-7.1.8/lib/src/auth_credential.dart').
      return _providers;
             ^
../../AppData/Local/Pub/Cache/hosted/pub.dev/vm_service-13.0.0/lib/src/vm_service.dart:314:30: Context: '_disposeHandler' couldn't be promoted because field promotion is only available in Dart 3.2 and above.
See http://dart.dev/go/non-promo-field-promotion-unavailable
  late final DisposeHandler? _disposeHandler;
                             ^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Flutter-Dart\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 14s
Error: Gradle task assembleDebug failed with exit code 1

已尝试无效操作

  • 执行pub get/pub update
  • 执行flutter clean后重建项目
  • 重启Windows并重新打开项目
  • 从GitHub拉取历史正常版本的项目副本,仍出现相同错误

解决方案

1. 升级Dart版本至3.2及以上

第二个错误明确提示当前Dart版本不支持字段提升特性,需升级Dart版本:

  • 打开项目根目录的pubspec.yaml,修改environment字段:
    environment:
      sdk: '>=3.2.0 <4.0.0'
    
  • 执行flutter pub get更新依赖

2. 调整firebase_ui_auth版本

第一个错误源于firebase_ui_auth-1.14.0的可空类型不匹配问题,需调整版本:

  • 打开pubspec.yaml,修改firebase_ui_auth的版本:
    • 升级至最新稳定版:
      firebase_ui_auth: ^1.14.1 # 或更高兼容版本
      
    • 或降级至已知兼容版本:
      firebase_ui_auth: ^1.12.0
      
  • 执行flutter pub get,随后执行flutter clean && flutter run

3. 清理全局Pub缓存(可选)

若依赖缓存存在异常,执行以下命令清理:

flutter pub cache clean

清理完成后重新执行flutter pub get


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 11:57:10