Update content file flutter without truncate - flutter

I´m working with files in my application, I´m taking this article as example https://docs.flutter.dev/cookbook/persistence/reading-writing-files, I can read and write the file succesfully, my estructure is the next
{
'products' : {my_items...},
'data_customer' : {info_customer...}
}
But my problem is, It´s possible update the content from 'data_customer', preserving 'products' information?
I tried use the FileMode.writeOnlyAppend, but this only append the info in the end of file, for example
{
'products' : {my_items...},
'data_customer' : {info_customer...}
'data_customer' : {new_info_customer...}
}
I just want to update the information. Thanks in advance

Read the file as string and use json.decode() method to convert it as Map<Sting, dynamic> then change the data and rewrite to the file after decoding it to JSON using json.encode() method.

Related

How to fetch the RecordTypeName Dynamically from the schema

Can anyone share the solution that 'How to fetch the RecordTypeName Dynamically from the schema' to store into custom object.
You can use below syntax to fetch RecordTypeName dynamically from schema by giving custom ObjectName from which you want to fetch the recordTypeNames.
Further you can save this recordTypeNames in a custom field of your custom object.
Schema.DescribeSObjectResult objDesc = ObjectName.SObjectType.getDescribe();
List<Schema.RecordTypeInfo> objRTList = objDesc.getRecordTypeInfos();
for(Schema.RecordTypeInfo recType : objRTList) {
system.debug(recType.getName());
}
If you find it helpful, Please mark it as best answer.
Thanks

How to cache a value returned by a Future?

For my Flutter app I'm trying to access a List of Notebooks, this list is parsed from a file by the Api. I would like to avoid reading/parsing the file every time I call my notebooks getter, hence I would like something like this:
if the file had already been parsed once, return the previously parsed List<Note> ;
else, read and parse the file, save the List<Note> and returns it.
I imagine something like this :
List<Notebook> get notebooks {
if (_notebooks != null) {
return _notebooks;
} else {
return await _api.getNotebooks();
}
}
This code is not correct because I would need to mark the getter async and return a Future, which I don't want to. Do you know any solution for this problem, like caching values ? I also want to avoid initializing this list in my app startup and only parse once the first time the value is needed.
you can create a singleton and you can store the data inside a property once you read it, from next time onwards you can use the same from the property.
You can refer this question to create a singleton
How do you build a Singleton in Dart?

phonegap-base64 plugin - how to use at the ionic framework

I added the plugin by using the link at cli.
Plugin: phonegap local plugin add org.apache.cordova.device
Plugin-Link: https://github.com/hazemhagrass/phonegap-base64
Now I did copy the code in my controller, but it does not work.
Code:
//filePath is the absolute path to the file(/mnt/sdcard/...)
window.plugins.Base64.encodeFile(filePath, function(base64){
console.log('file base64 encoding: ' + base64);
});
My question is, how do I activate the plugin? Like using for example "$cordovaCamera". Maybe somebody can show me a correct controller example. Thanks for your help.
Christoph, The base64 converting is very simple with this plugin , we just need to call this function and pass the file path to that function and it will retun the full base64 string :
here is a simple example :
// Loop through acquired images
window.plugins.Base64.encodeFile(filePath, function(base64){
alert("Base64 image : "+base64);
var base64Data = base64;
//Use this base64 where you wants
});
I hope it will help ypu to convert file to base64 .
have a happy code day

BlackBerry 10: Load GroupDataModel data into a JSON file?

I have a ListView in QML using a cpp GroupDataModel that is created from a .json file in the assets folder. Items from this ListView are removed and added to. In cpp how do I get the GroupDataModel data into the JSON file?
I know there is this:
JsonDataAccess jda;
jda.save(huh?, "/app/native/assets/employees.json");
How do I get the GroupDataModel data into a QVariant to put in the first parameter of that function? I can't just stick my m_model GroupDataModel in there; it causes an error.
You have to iterate over your model with GroupDataModel::data() and GroupDataModel::childCount() to create your resulting QVariant, then store it. As far as I know, there's no automatic way to do this.
Edit: there is one.
for loading groupdatamodel content in to json file, you have to do:
QList<QVariantMap> myList = m_model->toListOfMaps();
QVariantList membersList;
foreach(QVariantMap s, myList){
membersList << s;
}
JsonDataAccess jda;
jda.save(membersList,path);

Which file contains function of core/session in magento?

I need to customize other's code,
so I found they used
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
in Order.php file for custom order email
so I can't find this function getMyCustomBlockInfo();
Can anyone tell me where this function reside?
Thanks
those are magic functions get() and set() and you are asking a session variable there that is set as
Mage::getSingleton('core/session')->setMyCustomBlockInfo();
somewhere in your code. If you use terminal you can easily find by making a following grep:
grep '>setMyCustomBlockInfo(' . -rsni
and it will list the files where your variable is set to session.
example :
Mage::getModel('catalog/product'); //or
Mage::getSingleton('catalog/product');
the code must be in '../app/core/Mage/Catalog/Model/Product.php' file
then
Mage::getSingleton('core/session');
the code must be in '../app/core/Mage/Core/Model/Session.php' file
because the class Mage_Core_Model_Session's parent::parent is Varien_Object, then you can do all magic functions and you can ->getData() to see the Data inside.
Mage::getSingleton('core/session')->getData();
on your problem when go call ->getData() you can see data : [my_custom_block_info]
you can set it with call
Mage::getSingleton('core/session')->setMyCustomBlockInfo('what');
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
// will return 'what'