How much should presenters know about the view? - flutter

I have a Flutter mobile application where I do request data from the backend, and each individual record of this data have it's own identifier and category. For each of these identifiers I want to display them properly and also redirect the user to the correct page of the app. An example:
User enter the page, and we request the data
Data arrives and we present it.
When clicking at each item, we should redirect the user to the appropriate page of that item.
Question 1) Where should the route definition be?
Currently I created a Widget and made a switch case on the identifiers to define the route of each one click.
But shouldn't this be done already in the presenter, so the view would only display it and create the callbacks to redirect it with the given route? My concern about it is that then the presenter would know too much about the View, or am I wrong?
Question 2) Each of those items that I mentioned have their priority, and in the view each priority is displayed in their own way, like Urgent priority is displayed in red and so on...
Should presenter also define these colors for the view? The problem is that this Color it's an object from the Flutter Framework which I would like to avoid in this layer...
My current implementation is like this:
View calls controller (bloc) which call usecase that responds with the needed data.
Presenter (same bloc) gets this data and format the correct title for each identifier
The view gets the view model from presenter and displays it, but also need to do a switch case on the identifier of each item to know about the color of the item on the screen and also the route to be redirected when clicked.
Any help is appreciated.

Related

CRUD Pattern with API in Flutter

I have a REST API running on the server to create the object. In case there are any validation errors, the API returns 422 with error messages in the response. Simple.
What I am trying to do
Show a form to the user to fill in. When the user submits the form, show the loading indicator till the response comes back from the server.
In case the server responds success, then show the details of the object created on the server (basically an ID is now assigned). On back button, the form should not be shown but the widget from where the Form was launched should be shown.
In case the server responds with an error, then show a message and give the user a way to go back to the form to resubmit the form with changes. Ideally, it would be great if the form could be displayed automatically with a snackbar showing the error (or like a web form - errors on top of the form)
Constraint - I would like to avoid having to recreate the Form widget and re-use the one in the stack in case of API error.
Current Implementation
I have implemented a widget with a Form widget in flutter. On submit, When the form is valid, I save the form into a local model object. And then post the JSON representation of that object to the server using a service object.
The service object returns a Future of that model object which I use to create the next widget (view model details) and push into the Navigator stack. This widget, uses a FutureBuilder with this future that it receives in the constructor.
In case the FutureBuilder receives an error, I display a message with the button, where I pop the stack from the Navigator and go back to the Form view on click.
If there is no error, then this view displays the object details. But the back arrow in the app bar goes back to the previous Form widget.
Here the problems start:
If I use pushReplacement on the Navigator when loading the view that has the Future, then I can't just pop to come back to the Form on error. If I don't, then I come back to the Form even on success.
At present the only way seems to be to handle the Future also in the widget that has the Form and go to the detail widget only if the Future succeeds.But this does not seem a clean way with the Form widget doing too many things.
Is there a better alternative or pattern to achieve this so that I can pop the Form view in case the Future is successful?

two view in the same page

I am working with asp.net MVC2, I'm new in development. net
I have a view that contains 2 dropdownlist and a button, I want when I click the button, another view is displayed, I want both to appear on the same page
There is two way you can implement this
1) With Complete post back you can use Html.RenderAction or load the partial view. You can use some flag to differentiate between the first time page load and post back
2) You can use the jquery AJAX and call the controller action of another View and get the content and write it to the div of the page .
Please do some research work on both and I think you can get the result as you want.

Positioning ListViews in WinJS Metro apps using scrollIntoView

I am building a jscript-based Windows 8 Metro app. The main screen of this application is a scrolling "panorama" view with several list views showing various aspects of the app's state. In some cases the user will select something on the page which results in a navigation to another page (using the WinJS.Navigation.navigate method.
When the user hits the back arrow on the other page, it returns to the main screen, and I use "scrollIntoView" on to position the screen to the section that the user was working on before the navigation occurred.
Unfortunately this hardly ever results in correctly positioning the view. It seems random. I suspect that the page isn't finished being built yet and that the scroll values are set based on the state at some snapshot in time.
Now the question:
Is there some what to be notified by WinJS ListView objects that they are completely rendered and layed out? Or is this the job of the page's ready function?
Thanks for any insight!
Putting multiple list views side by side is Not A Good Idea(TM). I would recommend putting one list view, and placing your content in a grouped data source to get the groups. If the items have different templates, then you can use a custom item Template selector to dynamically select a template.
Additionally, to ensure that the list view is scrolled to the right position, you need to use the indexOfFirstVisible to set the items the name suggests.

Navigation in mvvm

I am trying to navigate on a frame with pages but instead of giving views to the page I am giving view models.
This works fine, but the problem is when I navigate between the pages the status of the radio buttons for example doesn't stay the same. It stays only if I use the views and not the view models.
Any ideas?
Thanks.
Some code to explain how you navigate between each control would allow us to give you more specific answers, currently we can only guess what you are doing.
It sounds like you are creating a new instance of each ViewModel when you are navigating between pages. This of course means things such as radio buttons and control states will not remain consistent.
You could use a framework such as MVVM Light and make use of their ViewModelLocator pattern. This means you could have one static instance of each ViewModel.
You could also store all of these states in a simple data model, and then simply have your new ViewModel instance refer to this model and update it's check boxes etc appropriately.

Asp.net MVC 3 partial view postback

I am new to mvc and I have a question
I have a page (asp.net Mvc 3) called profile which contains 3 partial view called (1) Address,Qualification,Experience.
Each of the partial view should allow you to add its details and save it details/contents without affecting the others.
How can I attach an action to each partial view save button and postback the result without refreshing other partial view.
Can someone explain this to me with and without using jquery/ajax
without ajax or jquery you'd be stuck with doing something horrible like iFrames... Stick to jquery, it is the best and easiest way.
Actually, here is one way you might be able to do it.
Name the "Submit" buttons according to the method you want called. Then, have all of your 3 sets of data inputs within one <form></form> which posts to an intermediate Controller endpoint.
In the intermediate controller endpoint, determine which button was pressed, then pass the correct data to your normal control methods, and push all the other data back to the view. That way you can fill out all the inputs, click the appropriate submit button, then only the correct data gets used! Then all the other data gets pushed back to the view and the approprate input boxes get filled out.