Bloc pattern in Flutter with Single page opening multiple times - dart

How do I implement Bloc pattern in Flutter where I want to open a page multiple times.
Suppose I have a detailed list, and from the detailed list I can click on an item and open the detail page of Item A.
The detail page has a bloc for it. From detail page of item A I can open detail page of item B and from detail that I can open detail page of item A.
Page stack: (1)A -> (2)B -> (3)A
Now for every invocation of a new detail page, should I create a new bloc? or should I have a global detail_bloc that manages a stack of opened detail pages. Also I need a way to update details of previous opened page of item (1)A if there are any changes (due to user input) on page of top level item (3)A.

Related

Is there an event listener whenever view is active after a navigator pop?

I have been developing an app using flutter, which has a bookmark section. In the bookmark page, you can click an entry to a view more page. While in the view more page, there is an option to unbookmark the entry.
Is there a way to communicate between flutter pages? Since, I want to sync the bookmarked entries between pages (in this case unbookmark the entry and updates the bookmark page once navigator pop is used). The initState() only runs once and will not be called on succeeding navigator pops, while didUpdateWidget() seems to inefficient.
Why not provide a method removeFromList(bookmark) to the ViewMorePage as a constructor attribute.
void removeFromList(bookmark) {
setState(() => bookmarkList.remove(bookmark));
}
The setState forces the widget to rebuild with the shorter list of bookmarks. Does that help?

How to retain values of dropdown with selected values in MVC?

The scenario is - There are two view in my mvc application. One is Index and other is for adding payment details. in index form I fetch details of a perticular client in that I have cascading dropdown one for selecting type and one for according to type select client in another dropdown, both are coming from DB's and on d same view I have an ActionLink for going on Payments view "for adding the payment details for the same client that is been selected on Index views second dropdown (first is for Type)".
My problem is that when I am going on Payments view and clicking back button of browser to go back on my index page it is clearing the second dropdown. and all other data is safe on the form. So can you please help me to avoid this so that all the data of my Index view should retain throughout the execution.
This also in case when I add Payment for that client and click submit it should redirect on the Index view with retaining all its previous data. that we have fetched on Index page.
with a message box Payment Added successfully.
You can save the current selected values of dropdown1 and dropdown2 into one of the followings:
URL
Session
Cookie
Then in the Index page you always check to read those values if they are existed to setup the dropdowns in the first request. Then do update those values again whenever user selects to update the dropdowns.

passing a list of objects from jsf page to another

I am new at JavaServer Faces (JSF).
I have a list of cars and after pressing the commandButton of my first page I want to show the list in the other page (the backing beans are RequestScoped).
I have seen examples where you can only pass String values.
if you have list of cars, it means you have data table or some another list which is coming from managed beans. if you want show whole list in the next page, you need just call the same list from next page.
if you want pass only one row /object, you should pass row/item id via f:param , in the next page from another managed bean you should handle id and call from database getItemById(id) and in the page show item.

Redirect based on page source

I have an edit page, which can be accessed from 2 list pages which are page A and page B (both performing about the same thing but is totally different). The edit is a part of the page B controller, and it has a delete function to delete any item from A or B.
The thing is, whenever i delete an item from page A or B, it will return to page B. This makes sense anyway since the edit page controller is the page B controller.
So how can i make it so that if the item is from page A, it will return to page A after delete, and if its from B, it will return to page B? I've been thinking of using 2 delete functions on page B controller but i guess that's not the effective way to handle this problem.

Displaying Grails domains in jquery tabs

What would be the best way to display data from Grails database in JQuery UI tabs? What I would like is to have a tab interface and on each tab is a list of the records from a different domain. For instance, Tab1 displays the record list from Domain1, Tab2 displays the record list from Domain2, etc.
I have the JQuery UI tab interface set up and working and am currently using createLink to call the method from the controller to return the model of the appropriate domain. The tabs look like this:
<div id="tabs">
<ul>
<li>Hardware records</li>
<li>Model records</li>
<li>Building records</li>
</ul>
</div>
The method from the controller looks like this:
def listHardware() {
[hardwareList:Hardware.list(), hardwareInstanceTotal:Hardware.count()]
}
I've also played around with rendering a whole GSP within the tab by using "render(view:'HardwareList', model:[hardwareList:Hardware.list(), hardwareInstanceTotal:Hardware.count()]", but that takes a VERY long time (at least 5 seconds) to load each time the tab is selected and is not at all ideal, especially if it were to take that long for each tab.
UPDATE
As noted in one of my answers to Rimero's answer below, I was able to use templates to display tables of my domains' data. I'm also trying to implement pagination on each tab using the tag, but each time I click on one of the pages to view another page, it takes me to the full template itself outside of the tab interface. Any thoughts on how to format the tag so that everything stays within the tab??
Here's my suggestion:
You can fetch everything at once in your controller in your index method for example.
You can implement your tab contents as templates
(g render template). Each tab == 1 template.
You can fetch your domain objects buildingList,
etc. from the index method of your controller.
The g:render template code for each tab may only need to be passed a map or a collection for rendering.
In this case you don't need hyperlinks to controllers endpoints. You just keep anchors to the tab(div id) as in the default example here -> http://jqueryui.com/tabs/.
UPDATED ANSWER
As you said that sending all the data at once takes a long time, you could fetch it asynchronously. If possible populate the data only for the first tab directly.
Create a business method for each tab, that will return the model as JSON, data is only fetched if not already retrieved from the server (Need to keep state or see for example if the tab id has some DOM nodes.
Using JQuery, when the DOM is ready, get the current tab and if you didn't fetch the data for the first tab eagerly, fetch it at this moment with the busy image spinning.
As soon as you select a new tab, you need to check if the data was already fetched, if not, you send an ajax call and your callback function populate the data in the tab div container for example.
Hope it helps.

Resources