Update Key value of Provider package? - flutter

I have a page that goes after the main page which has its own ChangeNotifierProvider. The key given in the main method of the first page is a static String stored in the ChangeNotifierProvider class that I use in the second page.
When I update this String key before Navigator.pop() into the first page, coming back to the second page still has the same old values.
I heard changing the key lets you refresh the Provider stored values, so how do I do it? Or else how can I make sure everything is reset once I click a certain button to go back?

I had thought that there was such a function like this in Provider but no, would've been useful.
For now my solution was to create constructor methods that set everything back, so I can call them before I navigate.

Related

How to change a value in a text field and have it show up on another screen (Flutter)?

I'm trying to have the user put information in a TextField on one screen and then save that info when they press "Save". Then I want this text to show up on another screen in another Container (say it asks for their name, they put it in the TextField, press the Button called "Save", it takes them back to the other screen, and the box that previously said "Name" now says "[The name the user entered]").
Thank you in advance for any help!!
Use StateManagement Libraries like flutter_bloc,provider,mobx, getX.
This way you will be able to save your data and use in in any part of your app
There are multiple ways of going about doing this.
You can pass the value through the constructors of the screens you're navigating to (for e.g.
MaterialPageRoute(builder: (context) => NewPage(name: nameValue))
If you want to use this value in multiple places in your application, you can consider storing it in a config class of sorts (i.e., create a class Config as a singleton (only once instance allowed), and store the name there while saving like
Config.name = nameValue. Then, anywhere in your app, you'd access it as Config.name)
If you want this value to be used anywhere else in the app, but also want it to be persistent, then it's probably best to store it as SharedPreferences or in a database. Look into the sharedpreferences package, or sqflite package for Flutter.

Problem showing a value contained in an InheritedWidget

I've been developing in Flutter for a few months and I'm not yet very experienced. These days I'm working on an app that I didn't create from the beginning and I'm having a strange problem, unfortunately I can't paste too much pieces of code but I try to explain the wrong behavior.
The state of the app is contained in an InheritedWidget that is called before all the others. For example, in this InheritedWidget there is a value that must always be visible at the top of the app (in the AppBar). The problem is that if at runtime this value is changed in the InheritedWidget, the view shows the previous value (as if it wasn't updated), but if I do Navigator.push() to a new page, the AppBar shows the correct value (i.e. the updated one). If I pop to the previous page, the old value reappears in the AppBar. If I put the app in the background and bring it back to the foreground, the correct value finally appears.
It seems that the view does not update even if the value changes in the InheritedWidget. I specify that before being displayed, this value is extracted directly from the InheritedWidget using context.dependOnInheritedWidgetOfExactType<InheritedWidgetName>(). I also specify that "updateShouldNotify" is set this way:
#override
bool updateShouldNotify(Session oldWidget) {
return true;
}
I wanted to ask if anyone knows what might be causing this problem.
Thanks in advance.

Get textfield's value from one activity to another

I have two activities
Class MainActivity{
//has a single button and
//invokes SubActivity
}
Class SubActivity{
//This activity several textfields
}
While SubActivity is alive, I press back button and go back to MainActivity.
When I go back to MainActivity again, I would like to get the textfield values from the MainActivity. I tried using context but it doesn't seem to work. Any suggestion is welcome.
You either have to pass them in a bundle with the intent to start the activity, write them to shared preferences, or put them in sqlite database. It's not possible to simply read data from another activity.

Wicket DefaultDataTable - Refresh it on browser back button

In my application I am using DefaultDataTable with SortableDataProvider which has LoadableDetachableModel as the model.
I used it to display a set of records ( say RecordList page). When I add or remove some records and load the page RecordList again, it displays the changes. However, if I use the back button of the browser and go the RecordList page which was rentered earlier ( before adding/ removing the records ). The DefaultDataTable still has the old sets of records. This is a big issue when records are deleted.
For example, If I delete a record and press back button then the page fails as the record it is trying to show does not exist in the database. Adding does not create an issue because it simply does not get listed in the set of records.
In another page, I just have PageableListView with LoadableDetachableModel. It works fine with out an issue.
There are one or two things that you can do about this.
First please check whether the data provider has the latest data.
Secondly make sure that the set of records with the Data provider is refreshed when the browser back button is hit. Ensure that the data fed to the Data Provider is refreshed in a method other than constructor. Because constructors will not be called when you hit back. So you would need to use a separate method. Ideally you could use the same method, but called from both constructor and when back button is pressed.

GWT Place objects

I'm new to GWT so this may be a dumb question but I didn't find a good answer to it anywhere.
So, how should I create Place objects in GWT? Should I create them as finals in my ClientFactory and reuse them everywhere?
the Place objects Eclipse generates eat a string token as their parameter what should it be?
My Understanding is the following: I should create final Place objects in my ValueChangeHandler for those pages that are static and reuse them everywhere. Those 'Place's that are relatively dynamic should be created like
new MyCoolPlace("MyCoolPlace" + someRandomNumber)
but isn't it kind of dumb using random numbers each time i need to navigate to a new page? also will the history be cleared of the objects which i created say hours ago?
Currently I have a problem with figuring out how this mechanism works:
I have a form. For, say, adding vegetables to the DB
1. User fills it
2. Submits it
3. Gets to a thank you page
4. Clicks a link in the menu to add a new vegetable
5. Gets to the form but it's already pre-filled with the values user previously entered.
I need the form clean on step 5. But if the user clicks the browser's back button on step 3 I want it to be pre-filled.
Question about final:
I think not. They are lightweight objects and places can have values into them. They are not a limited set of places values (at least if you parametrize them).
Question about form values:
The normal behaviour is when yo go back to -let's say- "vegForm" you obtain the clean view (it's because your URL token is simple vegForm). What happens I think it's you're reusing your view without initializing. Your presenter (or whatever has the UI logic) should obtain the view and call "reset()" "init()" or whatever you want.
If you want to hold your values when you go back you should save them in your place object. It is: field values. And your PlaceTokenizer (the object that transform between URL and Place object) should take care of them. By example: vegForm/potato,green,... (don't remember the standard notation).
The problem is how do you save into the URL the values you entered before clicking Save?
What I'd do is "saving" that state into the URL before saving:
History.newItem("vegForm/potato,green,...", false);
And that will get into the history stack. When I say false it means that the GWT History mechanism should not react to that URL avoiding loading the view again. When your user clicks back she should go back to form(with values). If your user clicks back again the she should go back to form(clean).
By example:
User clicks add veg -> #vegForm
User fills data and pless save
-> #vegForm/value1,value2 (saved in History with false argument)
-> #okPage
User clicks back
-> #vegForm/value1,value2 (form with saved data)
User clicks back
-> #vegForm (form without)
Initialization
Take into account you always must initialize the view.
If you don't have params, to clean it (it can be a reused view)
If you have params, to fill the form with them