firebase - “Query”类型不是“CollectionReference”类型的子类型
问题描述
我正在尝试按 date_posted 对我的数据进行排序,但我得到'类型'查询'不是类型'CollectionReference'的子类型。' 我曾尝试寻找解决方案,但都是徒劳的!我的代码:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:kopala_dictionary/models/words.dart';
class DatabaseService {
//cloud databse colection
final CollectionReference wordsCollection =
Firestore.instance.collection('words').orderBy('date_posted');
Future insertData(String word, String english_translation,
String bemba_translation, String user_id, DateTime date_posted) async {
return await wordsCollection.document().setData({
'word': word,
'english_translation': english_translation,
'bemba_translation': bemba_translation,
'user_id': user_id,
'date_posted': date_posted
});
}
//words list from snappshots
List<Words> _wordsFromSnapShots(QuerySnapshot snapshot) {
return snapshot.documents.map((doc) {
return Words(
word: doc.data['word'],
englishTranslation: doc.data['english_translation'],
bembaTranslation: doc.data['bemba_translation'],
);
}).toList();
}
//Stream snapshots
Stream<List<Words>> get words {
return wordsCollection.snapshots().map(_wordsFromSnapShots);
}
}
当我将其更改为:
final CollectionReference wordsCollection = Firestore.instance.collection('words').orderBy('date_posted');
我得到'类型'查询'不是'CollectionReference'类型的子类型'
解决方案
改变这个
final CollectionReference wordsCollection =
Firestore.instance.collection('words').orderBy('date_posted');
进入这个
final Query wordsCollection =
Firestore.instance.collection('words').orderBy('date_posted');
推荐阅读
- python - Pandas 将每月数据重新采样为每周在组内和拆分值
- android - 连接管理器 Android。检测重试/取消对话框按钮按下
- sql - 获取一段时间内的数据库统计信息(更新/删除/插入的数量) - PostgreSQL
- r - 如何为分组箱线图中的每个面板设置背景颜色?
- sql - SELECT DISTINCT 与 ORDER BY 和 CASE WHEN
- drupal - 发送到组的 drupal 电子邮件网络表单
- php - Codeigniter 表单发布数据为空
- reactjs - 如何在 Create React App 的 DevTools profiler 中获取到源文件的正确链接?
- javascript - 当合并流计数超过 17 时,Gulp 合并流未在异步函数中触发“完成”事件
- python - 如何将动态嵌套 json 转换为 csv?