Retrieve Flutter and Cloud Firestore data

shogo.yamada
1 min readJan 9, 2019

--

Save the data

Future<void> newGroup(
String title, String description, File selectImage, String uid,
bool isSecret, String secretWord) {
return Firestore.instance.collection("group").add({
"title": title,
"description": description,
"isActive": 0,
"make_user_id": uid,
"is_secret": isSecret,
"secret_word" : secretWord,
"created_at": new DateTime.now(),
"updated_at": new DateTime.now()
}).then((doc) {
if (selectImage != null) {
_uploadImage(selectImage, doc.documentID, uid);
} else {
_batchUserAndGroup(doc.documentID, uid);
}
});
}

get

Future<Group> getGroupInfo(String groupId) async {
var document =
Firestore.instance.collection("group").document(groupId).get();
return await document.then((doc) {
return Group.setGroup(doc);
});
}

The caller side is like this

var groupInfo = await helper.getGroupInfo(widget.groupId);
  • delete
Future<void> removeImage(String groupId, String groupDetailId) {
return Firestore.instance
.collection("group")
.document(groupId)
.collection("group_item")
.document(groupDetailId)
.delete();
}

How to use is quite similar to how to use Firestore on WEB developing.

--

--

shogo.yamada
shogo.yamada

Written by shogo.yamada

普段はエンジニアやってます👨‍💻 自分の資産運用の記録として書いてり、プライベートなことを書いていきます。

Responses (1)