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

安装firebase_firestore插件遇空安全错误,SDK范围来源存疑

问题

执行flutter pub add firebase_firestore时触发如下错误:

The current Dart SDK version is 3.5.3.

Because mpolice depends on firebase_firestore any which doesn't support null safety, version solving failed.

The lower bound of "sdk: '>=1.8.0 <2.0.0-dev.infinity'" must be 2.12.0 or higher to enable null safety.

项目的pubspec.yaml配置如下:

name: mpolice
description: "Ap"
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=3.3.3 <4.0.0'

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.8
  intl: ^0.19.0
  flutter_riverpod: ^2.5.3
  firebase_core: ^3.4.0
  firebase_auth: ^5.2.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^5.0.0

我的项目pubspec里SDK下限已经高于2.19.0,但找不到错误提示里的sdk: '>=1.8.0 <2.0.0-dev.infinity'范围,这个提示到底来自哪里?

解答
  • 这个SDK范围提示并非来自你的项目pubspec.yaml,而是来自firebase_firestore旧版本或其依赖链中的某个第三方包。
  • 你执行flutter pub add firebase_firestore时未指定版本,pub会尝试拉取兼容当前环境的版本,但你的项目已启用空安全(SDK下限3.3.3远高于空安全要求的2.12.0),而部分旧版本的firebase_firestore或其依赖包的pubspec仍使用<2.0.0的SDK范围,完全不支持空安全,导致版本解析失败。
  • 解决办法:安装与你现有firebase包版本匹配的空安全兼容版firebase_firestore,比如执行命令:flutter pub add firebase_firestore: ^5.3.0(版本号可根据firebase官方兼容表调整,确保和firebase_core、firebase_auth版本一致)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 06:55:14