I am new to flutter and am currently developing an app using the MVVM architecture pattern described in many of FilledStacks tutorials but am having issues with deciding what is the best way to manage context in the View Models.
I followed the Internationalization tutorial in the flutter docs for implementation of i18n and l10n which results in the need for BuildContext whenever a localized string is needed.
I am currently passing context from the Views build method as an arg to methods in which localized strings are used such as methods which return error text or for alert dialogues but this seems incorrect.
Is there a cleaner way to return Strings from the View Model without passing BuildContext as an argument while maintaining the "hot reload" of language if the user changes the device's language?
This question was answered for me on Reddit, I just wanted to add to it here in case anyone had a similar issue.
The basic premise is to use keys when using methods without context (such as in view models). Then use a translate function in the view when the context is accessible.
Related
I wanted to enable internationalization in my app. I am already using getx so i am going to use it to enable internationalization. However i had a confusion, in the getx page, there are these many languages that it supports. I was wondering if i would have to give a Translations class with the strings i want to only convert to these languages or would getx automatically do it for me. In other words, would i have to provide strings for these languages too, or will my text automatically be translated to these languages by getx
These languages are available for Getx readme file and if you click on them you will see a readme in that language,
You must provide the translated strings to Getx material app.
You can use google translate, Excel, or this VS Code extension to translate strings automatically
Please note i am not talking about the .abr files.
I have been following several tutorials on internationalization in Flutter using the intl package. I noticed that they always use a single AppLocalization class for storing all the messages that will be used in the application. Since it was a tutorial, I am wondering if we will always have to do it that way. I mean in a real application we will probably have hundreds messages to maintain. It would be a mess to put them all in a single class.
Maybe we should have a localization class for each Page?
What are your suggestions?
Flutter Intl package it's the right solution; also i used to Easy Localization.
This package has a "inherited widget " concept, so if you want to change automatically change UI for changed Local Language, it will be quite useful to you.
Maybe you want to localization JSON update to server and use application new key-value without deploy store. EasyLocalzation does read the server-side JSON file.
What is the correct way to open a modal dialog in WPF using the latest version of the MVVM Light framework. I also want to be able to pass values to the ViewModel of the window used as the modal dialog.
I cannot find any samples on the MVVM Light site.
You should use the DialogService which abstracts the visual representation of the view so that you can do "Show" within the view model (and later possibly/hopefully) mock it for testing.
More info on the DialogService here.
-edit- I was wrong, as Alan Rutter (OP) points out the IDialogService is only for simple message boxes. I don't think MVVM light will help you much here but you can build a similar service (e.g. ICustomDialogService?). Custom dialogs can register as available with the service, and then the interface provides calls that will allow you to invoke a specific dialog by name (String or Enum perhaps) and pass any parameters you want.
Dialogs can register with the service in a few different ways - can happen for the type in static constructors (that you somehow have to force) or more explicitly through attributes in assemblies. Possibly even using class attributes. It depends on your startup sequence and general infrastructure.
I'm having a little bit of a hard time getting into mvvm. I'm writing a simple app, Notebook. I have one viewmodel, it's name is actually ViewModel. It has an ObservableCollection of Notes inside and methods to save and load those from Isolated Storage. My only Model is Note.cs, it implements INotifyPropertyChanged and I'm of course RaisingPropertyChanged.
I've also got two view, both of them are user controls. One to display list of notes and one to edit the one chosen from the list.
My questions are:
Where do I create an instance of my vievmodel?
How should I implement going from the page with list of notes to the page with detailed view after choosing one Note to edit? At the
moment I'm saving the index of Note in App.xaml.cs, going to the next page and setting
the DetailedView DataContext to the right Note in OnNavigatedTo, but
I don't think it's actually the perfect solution.
Where should I save my Notes? I guess Application_Closing in App.xaml.cs is the right place to do it, but I'd have to have my viewmodel as a global object there, is this the right approach?
Additional question:
I have to add possibility to group notes. I guess that class Group with dictionary (GroupName, howManyNotes) is going to be allright since I don't have to be able to for example write all notes from selected group. Do you think there's a better approach I should think about?
Thanks for respones,
MichaĆ.
I would suggest you take a look at Calibrun.Micro which is a great framework for MVVM. You can get some sample from the CodePlex.
I have used that in a bunch of Project, and will give you flexibility in case if your project grows in size.
Google for Caliburn.Micro sample and you will find a number of sample for all technologies like WPF, Silverlight, Windows Store, Windows Mobile.
Caliburn.Micro CodePlex
We have been using GWT for around 4 years now. One of the most often discussed features missing in native GWT is data binding. Reading across AngularJs another Google offering, i came across http://devgirl.org/2013/03/21/fun-with-angularjs/ . I do not wish to use GXT or any other third party tools. I also wish to avoid generator related solution.
Is there any way this will ever be implementable in pure native GWT?
Is there any specific reason why GWT cannot provide this out of the BOX?
Have you tried GWT Pectin?
I have used it successfully in a larger project some time ago.
I suggest you try HexaBinding, which is non invasive and only focused on data binding. Here is the link : https://github.com/ltearno/hexa.tools/blob/master/hexa.binding/README.md
It works with pure Java, GWT and will soon work also with Android and JavaFX. It may even work with J2Objc but not sure yet...
I read the post you mention on devgirl about AngularJS. In that post the "2 way data binding" refers to the property of the code to reflect automatically on the view the changes that occurs to the data that the view is currently displaying.
This is achieved in GWT since version 2.1 with the Cell Widgets
In the first paragraph of the Cell Widgets documentation I linked above it is clearly stated that:
A cell widget can accept data from any type of data source. The data
model handles asynchronous updates as well as push updates. When you
change the data, the view is automatically updated.
If you want to do in GWT something as basic as the example in the devGirl post you need to write a onKeyup handler (in AngularJS you should write a Scope to this purpose) that would copy what you entered to the linked label. Something like this:
...
final TextBox nameField = new TextBox();
final Label enteredName = new Label("");
...
public void onKeyUp(KeyUpEvent event) {
enteredName.setText(nameField.getText());
}
...