How to get data inside data in flutter? - flutter

{"dynamic_link_data":{"data":{"referralCode":"1234"}}}
How to get referralCode inside data. I m not able to fetch referralCode from response.

If you have only one dynamic_link_data and also one data, you can try this:
var test = {"dynamic_link_data":{"data":{"referralCode":"1234"}}};
if (test.isNotEmpty && test.entries.first.value.isNotEmpty) {
print(test.entries.first.value.entries.first.value['referralCode']);
}

Related

How to dynamically read specific data from firebase realtime database using flutter

I am struggling to reference specific things in my firebase real time database. I understand that when you want to read something specific from the database you need to specify the exact path where the item can be found.
If you see the screenshot attached, I want a way to read the name of each menuItem and store them in a list.
It seems like this can only be done if you reference each menuItem ID individually in the path (like in the code below).
Is there not a way to say ("menuItem/itemID/itemName") so that I can access each menuItem name dynamically using a for loop with a terminating value equal to the number of menu items in the database?
Any help would be greatly appreciated!
final DatabaseReference _dbRef = FirebaseDatabase.instance.ref();
late DataSnapshot _itemStream;[![enter image description here][1]][1]
Future<List<String>> _readItemNames() async {
_itemStream = await _dbRef.child("menuItem/J1/itemName").get();
itemName = _itemStream.value.toString();
itemNames.addAll([itemName]);
_itemStream = await _dbRef.child("menuItem/J2/itemName").get();
itemName = _itemStream.value.toString();
itemNames.addAll([itemName]);
return itemNames;
}
If you want to read and process all menu items, you can do:
var snapshot = await _dbRef.child("menuItem").get();
snapshot.children.forEach((childSnapshot) {
var props = childSnapshot.val() as Map;
print(props["itemName"]);
});
For more on this, see the Firebase documentation on reading a list of items with a value event (you're just using get() instead of onValue, but the logic is the same).
There is no way to get only the itemName property of each child node, so if all you need it the names you're loading more data than needed. If that is a concern, consider creating an additional list with just the value(s) you need. For example:
menuItemNames: {
"J1": "Milk Shake",
"J10": "Name of J10",
...
}

Fetching json from Mongo with Meteor

I am trying to fetch a json object from the mongodb using meteor, but I have no clue why I’m unable to do so.
I need it to be a JSON object only.
One of the entries of the collection looks like this:
[Image taken from Meteor Dev Tools]
Link: https://i.stack.imgur.com/BxRmS.png
I’m trying to fetch the value part by passing the name.
Code on front end:
export default withTracker(() => {
let aSub = Meteor.subscribe(‘allEntries’);
return {
aBoundaries: DataCollection.find({}).fetch()
}
})(Component Name);
The Meteor Call Statement on front-end:
dataFromDb = Meteor.call(‘functionToBeCalled’, ‘Sydney’);
Server-side Code:
Meteor.publish(‘allEntries’, function(){
return DataCollection.find();
});
Meteor.methods({
functionToBeCalled(aName){
return DataCollection.find({name: aName});
}
});
Another of my questions is:
Is there any way that we publish only all the names in the beginning and then publish the values on demand?
Thanks for your help in advance!
I have tried this as well, but it did not work:
functionToBeCalled(aName){
var query = {};
query['name'] = aName;
return DataCollection.find(query).fetch();
}
The issue seems to be with query.
Collection.find() returns data with cursor.
To get an array of objects, use Collection.find().fetch(). The jsons are returned as collection of array like [{json1}, {json2}].
If there is a single document, you can access the json using Collection.find().fetch()[0]. Another alternative is to use findOne. Example - Collection.findOne(). This will return a single JSON object.
use Meteor.subscribe('allEntries'), do not assign it to a variable.
Meteor.subscribe is asynchronous, it's best you ensure that your subscriptions are ready before you fetch data.
Log DataCollection.find({}).fetch() to your console
Check this official reference https://docs.meteor.com/api/pubsub.html#Meteor-subscribe.
Your second question isn't that clear.
Just in case anyone comes here to look for the answer ~~~
So... I was able to make it work with this code on the server:
Meteor.methods({
functionToBeCalled(aName){
console.log(aName);
return DataCollection.findOne({name: aName});
}
});
And this on the client:
Meteor.call('functionToBeCalled', nameToBePassed, (error,response) => {
console.log(error, "error");
console.log(response, "response"); //response here
})
Thanks for the help!

Ionic 2 Modal multiple get data

sorry for my english, I try to get multiple data from a modal but this not work.
This is the code in modal.ts:
anadir() {
this.viewCtrl.dismiss(this.cantidad, this.idpedido, this.posicion);
}
and this is the code in page.ts:
myModal.onDidDismiss(data => {
this.idpedido = data.idpedido;
this.cantidad = data.cantidad;
this.posicion = data.posicion;
console.log(data)
});
The data that i get is "undefined", thanks for the help.
Instead of sending three different properties, you can try by sending a single object with three properties like this:
anadir() {
this.viewCtrl.dismiss({
idpedido: this.idpedido,
cantidad: this.cantidad,
posicion: this.posicion
});
}

Posting multiple images to tumblr using tumblr.js api

I am trying to creating a app which can send posts to tumblr using tumblr.js api.
I could send single image using the createPhotoPost method, but I have to send multiple image in a single post via this method.
From the documentation it says that createPhotoPost method has a "data" parameter which can be an array with "URL-encoded binary contents"
When ever I try to send something in the data Array it returns "[Error: form-data: Arrays are not supported.]".
Can someone please help to solve this issue and please explain what should we pass in the array (Really I am not getting what is URL-encoded binary contents)?
Thanks in advance
There is an error in tumblr.js
https://tumblr.github.io/tumblr.js/tumblr.js.html#line504
The documentation at https://www.tumblr.com/docs/en/api/v2#posting is correct.
Basically the issue is that its not supposed to be
data = [ one , two ] its litterally params['data[0]'] = one ; params['data[1]'] = two; (?A PHP Convention)
var request = require('request')// already a tumblr.js dependency
var currentRequest = request({
url:'https://api.tumblr.com/v2/blog/someblog.tumblr.com/post',
oauth:keys,
},function(err,response,body){
currentRequest//
debugger
cb()
})
var params = {
'type' :'photo',
'caption':'Click To Verify You Are A Robot',
}
var params_images = [
fs.createReadStream('image'),
fs.createReadStream('image')
]
// Sign it with the non-data parameters
currentRequest.form(params)
currentRequest.oauth(keys);
// Clear the side effects from form(param)
delete currentRequest.headers['content-type'];
delete currentRequest.body;
// And then add the full body
var form = currentRequest.form();
//###add params_images to params keys 'data[0]' 'data[1]' 'data[2]' ....
params_images.forEach(function(image,index){
params['data['+index+']']
})
for (var key in params) {
form.append(key, params[key]);
}
// Add the form header back
var form_headers = form.getHeaders()
for(var key in form_headers){
currentRequest[key] = form_headers[key]
}

Not able to update data of ParseUser class in Unity3D using Javascript

I am using this code to update data of a Parse User, but the data is not updating nor am I able to retrieve the data.
I am able to do update and retrieve the data for a ParseObject class created by me. Can someone tell me where I am wrong on this?
Out of all the debugs I have set I am able to see only the 1st debug "parse GetSync function passed" and the rest are not printing.
var parseUser: ParseUser;
function FBtoParse(){
var query = ParseUser.Query;
query.GetAsync("Q0D9eBvRee").ContinueWith(GetSync);
Debug.Log("parse GetSync function passed");
Debug.Log("Object ID: "+ parseUser["objectId"]);
Debug.Log("username is : "+ parseUser["username"]);
Debug.Log("User Updated");
}
var GetSync = function (t:System.Threading.Tasks.Task.<ParseUser>){
parseUser = t.Result;
};
function OnGUI{
if (GUILayout.Button("Parse"))
{
FBtoParse();
Debug.Log("Pressed Parse");
}
}
Parse at the moment only allows ParseUsers to update their own object through authentication.
https://parse.com/docs/js/guide#users-security-for-user-objects