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

Flutter导入geoflutterfire与cloud_firestore包报错求助

解决Flutter导入geoflutterfire和cloud_firestore包失败的问题

修复步骤

1. 调整依赖版本兼容性

你的firebase_core版本为^2.10.0,但搭配的cloud_firestore ^3.1.6版本过低,两者不兼容。同时geoflutterfire 3.0.3需要对应兼容的cloud_firestore版本,建议修改pubspec.yaml的依赖配置:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  location: ^4.4.0
  geolocator: ^9.0.2
  geocoding: ^2.1.0
  permission_handler: ^8.0.0+1
  firebase_core: ^2.10.0
  firebase_database: ^10.1.0
  collection: ^1.0.0
  meta: ^1.3.0
  geoflutterfire: ^3.0.3
  cloud_firestore: ^4.8.0 # 匹配firebase_core 2.x的兼容版本

注意:删除cloud_firestore_platform_interface和cloud_firestore_web,这两个是cloud_firestore的底层依赖,手动指定会引发版本冲突。

2. 清理缓存并重新获取依赖

执行以下命令彻底清理项目缓存:

flutter clean
flutter pub get

3. 重启IDE并刷新项目

  • 点击Android Studio顶部菜单栏File -> Invalidate Caches...,勾选Invalidate and Restart,等待IDE重启。
  • 重启后右键点击pubspec.yaml,选择Pub get重新拉取依赖。

4. 验证导入语句

确保代码中的导入语句无拼写错误:

import 'package:geoflutterfire/geoflutterfire.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 04:22:37