What should I use for i18n in Flutter: S.of(context) or S.current? - flutter

I'm using the i18n plugin for Flutter (I believe it's this one) that comes with Android Studio.
And in every example I see it says to use S.of(context).my_string to get the Strings but it always returns null.
If I use S.current.my_string, it seems to work.
So is S.current the right way to do it and every doc/tutorial out there is wrong, are they the same or what?
What I'm basically asking here, is what is the difference between them.

Seems like S.of(context) is initially available way to access localised string.
But sometimes you need to use it without Build Context (in ViewModel, for example). So S.current was added for these cases.
More info here

Related

Flutter: Localization from API call

I wish to localize a Flutter application where locales are fetched by an API call, given the requested language.
I was hoping to be able to use the Intl package or something similar, but I am not sure this is possible without the .arb files.
Any ideas on how to accomplish this without reinventing the wheel?
(Having the localizations stored locally is not an option)
Down below, you can see a class which is converted to a singleton pattern. You can use any service locator package. It will be the same thing.
Now you can call this class in your main function, default set to EN.
Now let's say, you want to support SPANISH and not want to use .arb files
Now you can call google translate and replace values with the existing one. for every variable. I hope this helps.
Use https://pub.dev/packages/localizely_sdk package, it provides what you want to achieve
Turns out easy_localization has the functionality described. Simply creating a custom HttpAssetLoader and passing it to the easy_localization initialization method works out of the box, and provides device language detection, and application rebuild on locale change as intended.

reuse result of initialize method from video_player flutter package

Is there option to reuse result of initialize method for video_player package? It takes time for complete - it would be great to cache it (eg. memory level) and reuse it when you back to before used video - and simple use cached data instead of wait for initialize result. I need it for intensive switching between videos.
There is a package called cached_video_player which may help resolve your problem. Check it out here.
I think you are asking about having the screen/page/widget pre-render. That is not currently supported by flutter according to this issue filed on github:
https://github.com/flutter/uxr/issues/6#issuecomment-881918751
Sure, but this is not very scalable and will quickly turn into a mess. It's much simpler and more flexible to just give MyRoute someway it can cache the next route, and then show that cached route when it needs. But flutter doesn't support this as everything needs to be 'on-stage' before it can be initialized. In AIR, or Unity, I could simply construct my new page, and it would begin loading data, I could then toss it on stage whenever I want.
PS. You probably already know you can pre-cache the video data/file itself.

Call a Dart const from a String version of its name

I am using Flutter and the FontAwesome library and I need to create icons based on their name. So, I need to get the following:
FaIcon(FontAwesomeIcons.lightWalking);
...but from its name as a String.
Something like this:
FaIcon(FontAwesomeIcons["lightWalking"]); // <== this doesn't work in Dart
I can then build a function to return icons based on the name that I get out of a database.
I don't think this is a dart related question on first sight but rather a FontAwesomeIcons question unless you want to use reflection in dart. You need to access the Icons here which are simply not accessible the way you tried it.
See the following issue:
https://github.com/fluttercommunity/font_awesome_flutter/issues/102
Quote:
Hi, we don't support icon maps officially, but you can use this
generator by calling it in the updater tool. You will need a local
installation of font awesome for this, please follow the instructions
for pro icons and ignore steps that mention icons.json or .ttf files.
If you need further assistance feel free to ask.
That means the way you are trying to access your icons is not supported directly.
However you could use the generator tools to create such a map, iterate it and find a suitable icon. See the FontAwesome example for that (they generated a map and iterated it).
https://github.com/fluttercommunity/font_awesome_flutter/tree/master/example/lib
What might be a little more convenient might be a third party tool which already has such a map and allows you to search it.
https://pub.dev/packages/icons_helper/example
You can then do the following:
getIconUsingPrefix(name: "PREFIX.ICON_NAME")
You can achieve this only using reflection. There is a library called reflectable for Flutter. It will generate some code for you and then you will be able to access the class members of FontAwesomeIcons by their name as String.

How to debug with createJS's objects

I am using createJS for a game, but when I debug the code with console, I got all objects displayed as an a. Then I have no idea what the object really is.
What does the a here mean? And what's the best way to debug these code?
This is due to the minified source. Instead, use the combined source. You can get a combined version of each library in GitHub, which is one file containing all the classes, but just appended, instead of minified.
If you are using the full combined suite on the CDN, then you can change the path to .combined instead of .min: https://code.createjs.com/createjs-2014.12.12.combined.js
Cheers.

How to remove id location strategy from Selenium IDE

the problem is: my web application uses ZK, which automatically generates random UUID for each web element.
When I try to record some basic test-case with Selenium IDE, it automatically tries to use these randomly-generated ID's, without even giving me a good alternative.
Is there a way to forbid Selenium IDE to use IDs while locating elements?
Possible workaraounds:
Implement ID generator in ZK: I've thrown away this possibility, because the application GUI is too complex for this task, and ID should be unique for whole sesion, which make this workaraound really hard to implement, when you have same elements on different page.
Find another recording tool: I've only found XLT script developer, which does the work by writing DOM-path using classes (which zk gives plenty) - but sometimes the location strategy gives false path, which is then not reproducible. Any good alternatives here?
You can change locater builder by changing the order of the locater in options>locater builder.
For example if you want to give first preference to css: name drag it on the top so when you start recording it will first give the preference to css name
Hope this will help you