我正在使用Firebase用flutter(dart)建立带有文章和食谱的应用程序。显然,文章有多个食谱,而一个食谱可以有多个文章(很多到很多)。
我已使用google提供的列在数据库中设置了引用。但是如果我不应该在模型类中使用Firebase.instance,我什至没有考虑如何使用它来填充它。
import 'package:prepmilecookingfeed/model/activity_feed.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class Activity_Home_Mobile {
final DocumentReference reference;
final List<String> activity_feed;
final String title;
Activity_Home_Mobile.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['title'] != null),
assert(map['activity_feed'] != null),
title = map['title'],
activity_feed = map['activity_feed'];
Activity_Home_Mobile.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference);
// @override
// String toString() => "Record<$name:$votes>";
}
final List<String> activity_feed;
expected => final List<Article> activity_feed;
class Article {
final String name;
final String desc;
final String likes;
final String picture_id;
final String quick_desc;
final String steps;
final DocumentReference reference;
Article.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['name'] != null),
assert(map['votes'] != null),
name = map['name'],
likes = map['name'],
desc = map['name'],
picture_id = map['name'],
quick_desc = map['name'],
steps = map['votes'];
Article.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference);
// @override
// String toString() => "Record<$name:$votes>";
}