将值从颤动发送到实时数据库 firebase

时间:2021-05-16 13:32:26

标签: firebase flutter dart firebase-realtime-database

我想在单击 onPressed 时发送特定值 0 或 1。

这是我的代码:

openGatePhoto() async {
    await Firebase.initializeApp();

    
    DatabaseReference referenceData =
        FirebaseDatabase.instance.reference().child("picture_has_changed");
    var picture_has_changed;
    if (picture_has_changed == 0) {
      picture_has_changed = 1;
    } else {
      picture_has_changed = 0;
    }

尝试导入包 import 'package:firebase_database/firebase_database.dart'; 时发生此错误:

Target of URI doesn't exist: 'package:firebase_database/firebase_database.dart'.

它显示 Undefined class 'DatabaseReference'Undefined name 'FirebaseDatabase'. 我查了一下,它说这可能是因为我的图像核心和 Firebase 存储版本,以及当我尝试更新它们时

firebase_core : ^1.0.0
  image_picker: ^0.6.2
  firebase_storage: ^8.0.0

发生此错误:

Because firebase_storage >=8.0.0 <8.0.1 depends on firebase_storage_web ^1.0.0 and firebase_storage >=8.0.1 <8.0.2 depends on firebase_storage_web ^1.0.2, firebase_storage >=8.0.0 <8.0.2 requires firebase_storage_web ^1.0.0.

And because firebase_storage >=8.0.2 <8.0.4 depends on firebase_storage_web ^1.0.3, firebase_storage >=8.0.0 <8.0.4 requires firebase_storage_web ^1.0.0.

And because firebase_storage >=8.0.4 <8.0.5 depends on firebase_storage_web ^1.0.4 and firebase_storage >=8.0.5 <8.0.6 depends on firebase_storage_web ^1.0.5, firebase_storage >=8.0.0 <8.0.6 requires firebase_storage_web ^1.0.0.

And because firebase_storage >=8.0.6 depends on firebase_storage_web ^1.0.6 which depends on http ^0.13.0, firebase_storage >=8.0.0 requires http ^0.13.0.

So, because LPP depends on both http ^0.12.0+2 and firebase_storage ^8.0.0, version solving failed.
pub get failed (1; So, because LPP depends on both http ^0.12.0+2 and firebase_storage ^8.0.0, version solving failed.)

我只想做的是,当您按下按钮时,它会将 0 或 1 发送到 firebase 上的实时数据库。有没有比我尝试过的更简单的方法。提前致谢:D

1 个答案:

答案 0 :(得分:0)

您必须确保所有软件包都相互兼容。这些是最新的兼容版本:

cloud_firestore ^0.16.0+1
cloud_functions ^0.9.0
firebase_auth   ^0.20.1
firebase_core   ^0.7.0
firebase_crashlytics    ^0.4.0+1
firebase_storage    ^7.0.0
firebase_messaging  ^8.0.0-dev.15
firebase_remote_config  ^0.8.0-dev.0

这是指南: https://firebase.flutter.dev/docs/migration/