Until now, I have been uploading my firebase database as follows:
try {
_firestore.collection('activity').doc(docID).set({
DateFormat('MM-dd-yyyy').format(dateTime): {
'host-$listOfAcceptedPlayers': {
'levels': [selectedRange.start, selectedRange.end],
'listOfAcceptedPlayers': [listOfAcceptedPlayers],
'numOfPlayers': '${_amountOfPlayers[_selectedPlayer]}',
'time': [
DateFormat('HHmm').format(dateTime),
DateFormat('HHmm').format(endDateTime)
],
// 'time_end': '${DateFormat('HHmm').format(endDateTime)}'
}
}
}, SetOptions(merge: true));
} catch (e) {
print(e);
}
Although because I am unable to parse the response from the server since it gives me a non JSON response (no ""), I am trying to update the way I upload my code to the following method:
var bodyHost = {};
bodyHost["time"] = [
"${DateFormat('HHmm').format(dateTime)}",
"${DateFormat('HHmm').format(endDateTime)}"
];
// var numOfPlayers = {};
bodyHost["numOfPlayers"] = "${_amountOfPlayers[_selectedPlayer]}";
// var listOfAcceptedPlayers = {};
bodyHost["listOfAcceptedPlayers"] = "$listOfAcceptedPlayers";
// var levels = {};
bodyHost["levels"] = [
"${selectedRange.start}",
"${selectedRange.end}"
];
var host = {};
host["host-$listOfAcceptedPlayers"] = bodyHost;
var date = {};
date["${DateFormat('MM-dd-yyyy').format(dateTime)}"] = host;
String str = json.encode(date);
print(str);
_firestore.collection('activity').doc(docID).set({str});
Although I am getting the following error The argument type 'Set' can't be assigned to the parameter type 'Map<String, dynamic>'. (Documentation). What is the right way to go about this?
If there is a way to parse the original response please let me know, just one thing to note - the "host-listOfAcceptedPlayers" will change every time I read it, and I want to capture what the listOfAcceptedPlayers is to then pull the data beneath it in the tree. The easiest way would be snapshot.data['levels'] (for example) although I cannot access the tree without knowing the listOfAcceptedPlayers (and how many/what the list of different emails would be).