how to save state in flutter am trying to make a quantity number which is displayed in text widge there is plus and minus button once I go back from the page the quantity becomes zero even though i have made it any other number
Since your use case is simple , it only requires storing the requisite data to JSON or UTF-8 and writing this data to an editable File.
1.Saving data as JSON
The dart:convert library has converters for JSON and UTF-8, as well as support for creating additional converters. JSON is a simple text format for representing structured objects and collections. UTF-8 is a common variable-width encoding that can represent every character in the Unicode character set.
2.Creating and saving to an editable File
The I/O library enables command-line apps to read and write files and browse directories.
You can used the provider package in Flutter to manage your application state.
Here is the link to the provider package and it's documentation.
Provider Package
Provider Documentation
When asking questions on StackOverflow, it's generally preferred to share some code that you have tried.
In your case, it's likely that you need to use setState in your widget somewhere to modify the value of a variable in your widget class. But without seeing your code, it will be difficult to answer completely.
Related
I am new to flutter and I found load csv from local and display as listview but I want to load from url and display. How can I do that?
A .csv from a remote source will probably have the content type of text/csv.
You should be able to call the url using a library (https://pub.dev/packages/http is a good choice, although I hear good things about Dio and probably a few others I haven't come across), get the data (e.g. as a http.Response), parse the response into some sort of model and then display it within the list view. Ideally the differences between displaying data from a local and remote source would be minimal - just where the data is coming from. This means you should be able to reuse the code you've written to load the data from a local source.
Without more information its hard to help. There's a good tutorial on building out Flutter apps using the Clean architecture at https://resocoder.com/category/tutorials/flutter/tdd-clean-architecture/. The difference will be that the Response data will be csv rather than JSON, so you'll need to sub in what you've done for the local loading.
In a web application, a first idea of storing a text message that contains a custom emoji is to save the link of the emoji within the text.
For example if the Messages collection has a content field, that field would contain the following when an emoji is saved within the text:
I am an example content with an emoji icon <img src='assets/emojis/custom-emoji.png'/>
I am not sure if this is the best way, and I would like to know what are the recommendations for this kind of situation.
I would recommend storing them in some symbolic way e.g. {emoji:smileyface}. This will allow you to update image paths without doing any data migration in the future. It will also allow you to do things like theming.
You can do the mapping in a variable on the client or server and at the point of retrieving data map symbol -> path.
I decided to raise the issue here. I use mysql as the database as a storage and would like to add draft-js into the web page I am building now. What is the correct way of getting and saving data into the database? Any working examples would be great!
You should use convertToRaw and convertFromRaw methods. Extracts from documentation:
convertFromRaw(rawState: RawDraftContentState): ContentState
Given a raw state, convert it to a ContentState. This is useful when
restoring contents to use within a Draft editor.
convertToRaw(contentState: ContentState): RawDraftContentState
Given a ContentState object, convert it to a raw JS structure. This is
useful when saving an editor state for storage, conversion to other formats, or other usage within an application.
I forked this pen for demonstration how these methods work. Open my pen. First, let's consider a saving editor state. I added "Log editor state" button. If you open console and click on the button, you can see current representation of editor state as JavaScript object. You can convert this object to JSON and save this JSON in your database using the appropriate API endpoint.
click to image for full size
The case when you need to show your editor on the page not empty, with a predefined content which you had previously saved in database or, for example, localstorage. Here, you should use createWithContent method and mentioned above convertFromRaw method. In my example I stored JSON string in the variable editorStateAsJSONString, for a real-world case you should request API endpoint, which returned JSON, and, after it, render the editor component as described.
I am new to GWT, and facing one problem.
How we have .properties file for initial configuration at startup.
I want to create one in GWT App.
Also, GWT has client and server package.
I want to setup the configuration at client package because all configuration belongs to client side.
My actual need,
I have one textArea which takes up only fixed number of characters and length is defined in my properties file like below.
So I have to read a properties file for validation.
my.properties
smsConstraintEnabled=true
smsConstraintCharLimit=160
I found few link but all are talking about properties file regarding Locale, I don't have any need on Locale side but need simple key-value configuration.
I want this file to be loaded at startup or at Entry point itself and then I can use it at any client package classes for my validation.
Thanks in advance.
Use a Constants interface. It's built with I18N in mind but will work just as well in this case, where you provide the constant values for a single locale, the default one (therefore used for every locale you'll compile your app with).
That however means the file is read at compile-time, not runtime (i.e. you'll have to recompile your app each time you change the properties file).
If you want something more dynamic, then read the file on the server-side and pass the information to the client-side. Easiest, and with minimal overhead, is to use a dynamic host page. To read the values in your client code, then either use a Dictionary (and Integer.parseInt et al.) or use JSNI (possibly with an overlay type).
I am working on a Zend Framework, MVC, enterprise website project. I would like to develop a friendly translation system with the ability to translate each word according its context (sometimes same word have different translation).
Zend Framework uses Zend_Translate for i18n and localization. We have also seen Magento's (which uses ZF) inline translation system, where users can translate pages directly.
We want to know how this inline translation system works, so that we can build a similar system with improvements.
Where are translations stored: in the database or in CSV files?
How does the system know to fetch translations for the same word when tranlsated differently by the user on different pages?
How should we build a page to support inline translation?
How does the system handle static text vs. dynamic (database-driven) text?
Inline translation seems like it would make the site very slow. How does Magento solve this problem?
Please if you have more points that should be explained, write them. Thanks
Starting from the beginning here (in the future, this is probably more than one logical question):
Magento stores basic translations (provided by the programmer) in CSV files, but inline translations are stored in the database.
Magento's translations operate on entire strings, not words. By providing an entire sentence worth of context for translations, idiomatic translations are achievable. The tradeoff is obviously that every sentence must be translated, rather than every word.
Magento's answer to this is to wrap all localizable strings in a call to the localizer. Magento templates usually look something like this (the double-underscore function maps to the "translate into the current locale" function):
print $this->__("Please translate this string");
Dynamic text (as in product descriptions) in Magento is often not translated, but if you want to do so, it's as simple as passing the right string to the translator, like this:
print $this->__($someString);
It's unlikely that translation will make or break your site (look to your DB queries for most performance problems), but this is a legitimate question nonetheless. Magento does a few things to help. First, it stores serialized versions of the CSV files in a cache, so that reading CSVs is made more efficient. Secondly, Magento offers page caching so that an entire page's output can be stored (assuming that it will render identically), as well as block-level caching for smaller bits of a page. Between these you're in good shape for the most part.
Hope that helps!
Thanks,
Joe