Flutter - Storing Widgets in Firebase? - firebase

I am wondering whether it is possible to store Widgets(code) in Firebase?
Reason:
I want the user to create a form that is specific to that user, so they can add / remove fields. Clients of the user can then fill that form out based on what fields the user wants.
I have read in other Stackflow Questions for other languages that they convert the code .toString() and store it as a String.
Any feedback would be appreciated!

Storing widgets won't be that much standard. See, the type of fields aren't infinite. What's infinite in your context is how many fields one user can have and the sequence of input fields (Just like a Google Form creation process).
One idea is that you store the sequence of input fields the user has selected and in each sequence you store the label, placeholders of those input fields which are common. Then retrieve those data from fire-base and display with the help of enum.

Yes, you are correct, it's possible to store codes in Firebase, using Flutter. As you mentioned, using the toString() - described in the official Flutter API here - it's possible to override and convert any formats to String, which can be stored in Firebase as you prefer.
However, please, consider checking and verifying the code added, as this is not the better solution and won't be able to add any code to your application as a field. Adding to that, when the code is brought back from the database, you should be able to use it as fields, once you convert the code.
Let me know if the information clarified!

Related

Changing data model in existing cloud firestore collection?

Suppose I have a users collection. The users collection has a large number of documents in it. Now in my app, I have a feature request that forces me to add or remove a field in my users collection data model. How can I add a new field or remove an existing field from all my users documents? Is there any best practice that the community recommends here?
How can I add a new field or remove an existing field from all my users documents?
While #AdityaNandardhane solution might work, please note that if you have a lot of documents, then you have a lot of update operations to perform, which also means that you have to play a lot of writes.
So the best approach would be to perform the update, only when the user reads the document. When it comes to users, most likely the details of the users are displayed on a profile screen. This means that when the users want to check the profile, before displaying the data, check for the existence of the new field. If it doesn't exist, then perform the update operation, and right after that display the data, otherwise, just display the data. This means that you'll have to pay for an update operation only when needed. It doesn't make any sense to update all documents, of all users, since there may be users that will never use their accounts anymore. So there is no need to pay for them.
As I understood, You can do the following thing
1. Add New Field
If you are using Firebase Functions- you can create one function and write an update query with a new field and set one default value and Run the function. You can do the same from android also with kotlin/java.
2. Remove existing Field
If you are using Firebase Functions- you can create one function and write a query to delete one field and Run the function. You can do the same from android also with kotlin/java.
Look for a better approach If any, Its suggestion as per my knowledge.

How do you display user values safely when using Firebase?

I've currently been setting up a website that uses Firebase Auth as its authentication system. When I was reading through the docs about getting information from a user's profile, I came across this text.
Be careful when setting (and later displaying) potentially user-facing UI values like displayName and photoURL. The API does not filter the values to prevent potential XSS-type attacks.
I was curious about how one would go about safely displaying a user's displayName to prevent XSS-type attacks?
Since users can insert anything they want in the displayName and photoURL values in their profile, it is important that you always treat those values as potentially dangerous and don't mix them with your code.
If you're directly inserting the values into the DOM/HTML in client-side application code, the best way to do that is through a property like textContent which will automatically encode any non-text values.
Similarly in server-side code, you can use a HTML encoding function of your platform, like this one for .NET.
For more on this, see:
Is it safe to display user input as input values without sanitization?
Safe Way to Include User Text Input in HTML
Show HTML user input, security issue

Marketo High Watermark and Field Definition Metadata Missing From API

Marketo Activity object API's missing High Watermark / Audit Fields. What is the potential way to identify changed records using UpdatedAt or ModifedDate like columns. None of the Activity Objects having this Audit column. What is best possible way to identify delta considering API limits
Also Is there any specific Object in Marketo for Field Metadata, which can be retrieved dynamically based on each Object filter to make the orchestration Dynamic. Basically looking for a system table in marketo which can be used as a data source and each Marketo object can be passed from Grid Variable to store the Field names in to a separate grid variable to use later
Did anyone face this kind of scenario before? Please share your experiences
Similar to this question, according to the Marketo Bulk Activity Extract REST API reference, the low- and high-watermark points are determined by a mandatory filter on createdAt. There is no concept of updating Activity records.
Regarding field metadata, you maybe need Custom Activities or Custom Objects? The API describes a Get Custom Activity Types endpoint which I think is the system table you are looking for.

Counting unique post view by uid

I am trying to build a mobile app which has a NewsBulletin feature using a NoSQL Cloud Firestore. I am trying to get the unique post view by keeping the user's uid into an array called "views" and count it by getting the length of the array. Is this recommendable or are there other better solution for this? Thank you
Currently this is the structure of my database:
News(Collection)
-DummyNews1(Document)
-newsTitle
-posterName
-bodyMessage
-timeCreated
-views(array)
-dummyuid1
-dummyuid2
I like your solution as it is easy to implement. You don't actually have to manually check for duplicate uids, as firestore has a built in feature that does that for you.
Here is an example:
FirebaseFirestore.instance.collection('news').doc('documentId').update({
'views': FieldValue.arrayUnion([viewerUid]),
});
FieldValue.arrayUnion will check if the contents exists in the database, and only when it does not will add the content.
Now, although I am a fan of you solution, and I do use this method for like type of feature in my own published apps, there are some limitations that you should be aware in case your app becomes super popular.
Maximum document size in firestore is 1MiB. Since firebase auth's uid is 28 characters long, that would be about 37,400 views maximum to be stored in a document ignoring other fields.
But if this is a new application, I would not worry too much about this limit. Besides, once you get close to this limit, you should have more than enough resources to pivot to another method that scales.

Decoding device information from user agent

Recently, I've add the user agent string when the guests submit the form to the database. There is a report that is generated weekly containing various statistics. I want to add the device and maybe the browser information to the report.
I was pondering that I would create a new database table that would hold all the know user agent strings and have two extra fields, one for the device info, and maybe the browser in the other one. However, I cannot find a site that you can download the strings. Would any one know of a place?
If that can not be done, I was thinking of a .net alternative. How would I go into doing that in .net?
2 ways to do it:
If you are using ASPNET MVC, you could use the default this.Request.Browser within the controller method call (contains quite a lot of info, example here),
You can also use 51Degrees, which has a light and a complete device db to match devices capabilities

Resources