我正在尝试使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference productsRef = rootRef.child("products");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String product = ds.getKey();
Log.d("TAG", product);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
productsRef.addListenerForSingleValueEvent(eventListener);
但是我遇到了这些错误:
Undefined class DatabaseReference
Undefined class FirebaseDatabase
Undefined class DataSnapshot
等等。
在build.gradle(app)内部,我有以下实现:
dependencies {
...
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-firestore:21.3.0'
}
我想念什么?
答案 0 :(得分:1)
在pubspec.yaml
文件中添加FlutterFire插件,如下所示
dependencies:
flutter:
sdk: flutter
# Add the dependency for the Firebase Core Flutter SDK
firebase_core: ^0.4.0+9
cloud_firestore: ^0.12.9+5
firebase_database: ^3.1.0
遵循此link以获得更多详细信息