Anyone Please Help. Listview on flutter not updating - flutter

https://i.stack.imgur.com/8yq5w.png
when I click 1st time on Shirshak it doesnot open anything. When I try to click on mobile 2nd time on Shirshak it opens new Screen https://i.stack.imgur.com/4fVMN.png. And when I click 3rd time on mobile in 2 then It opens Shirshak again. But when I click it 4th time then it opens 2 https://i.stack.imgur.com/kqEqv.png . This happens again and again I have to hit same two times to get inside chat screen in flutter.
Here is my code:
https://i.stack.imgur.com/iGYfZ.png
https://i.stack.imgur.com/MdY1G.png
https://i.stack.imgur.com/tIUKh.png

The function getDataForChat() in line 97 is an asynchronous method but you didn't use await and ansync keyword for it ( many other method which collect data from the internet in your code isn't marked with async and await too).
You should disabled all the other button when anyone of them is clicked .
You are using a Stateful Widget, so to change the value of any variable, you must use setState . For example, in line 101, you should use setState to set isLoading to false.

Related

How to update state when Navigating back to a page Flutter

i am creating a social media like app, when user clicks on post ,it redirects to a commentpage,in commentspage data is coming from a seperate API,so when go back using Navigator.pop(context), the data in home is not updated, if pressed like button,its not reflecting in ui, but updating in Api,
i wrapped Navigator with setstate but its not reflecting,
Use this on navigator push Navigator.push(context).then((value)=>setState((){}); when it pop the screen it will run the setState
Use this sentence to go to the second page so the function will wait second screen to close
bool result = await Navigator.push(context);
if(result){setState((){});}
when u close the second screen use this sentence Navigator.pop(context, true);
so when u comment has been posted successfully, u will back to screen one and complete the function if result boolean is true, else do nothing.

updateDisplayName in action without reloading simulator

In my code, I have firebase auth and I get the current user as:
User user = FirebaseAuth.instance.currentUser!;
To display the user name in a Text, just use Text(user.displayName)
To test the update functionality, I created a simple button and on onPressed I have
user.updateDisplayName('Test').then((_) =>user.reload());
How to "notify" the Text that the data has changed and change it without needing to reload the simulator?
--> this code is in a drawer
Since you're using Flutter, you'll need to store the value you want to re-render in the State of a stateful widget, call setState() when the value is updated, and then render it from there in your build method.
I recommend checking the documentation on StatefulWidget for an example of this, and more explanation than I can ever repeat here.

How to hide update dialog box when app is running for the first time in flutter

I am using upgrader package for showing dialog box telling user to update the app. Now, I don't want it to pop up when user is opening the app for the first time. How should I achieve this? Is there a field where I can put some kind of condition which can be true/false and accordingly it will show me the box?
You can use shared preference to save the value. for example, you can set an integer value with the name isTheFirstTime and set it to 0 which you can consider as a false.
and when you run the app for the first time it will check this value which is false and put this condition before your widget:
if(theValueYouChecked){ yourWidget }
At the first time, theValueYouChecked will be false, set the value in your dialog function in the shared preference to true so that when you run the app any time except for the first time you will get true so your widget will appear.

Flutter: Update specific screen using provider that's consumed in multiple screens

I have a typical CRUD operation task: (List Sites, Add Site, ...)
I created a SitesProvider. In the same provider, I added 2 methods for add and edit. I was thinking to use the same provider in the 2 screens (ListSites and AddEditSite)
In the ListSites screen, it works fine. Here is the problem:
I open the AddSite screen by clicking the AddButton in the ListSites screen
Hit submit (did not enter data, simulating error case)
The error gets displayed in the ListSites screen, not in the AddSite screen.
It makes sense. They both use the same provider, both screens are on the stack. It seems that the first one only consumes the state update and displays the error.
I use MultipleProviders approach that wraps the MaterialApp with all providers in the app.
Can we fix that without creating separate providers for each of the 2 screens?
EDIT:
I used provider.removeListener in the ListSites screen right before I open the AddEdit and it shows the error in the correct screen now. I still have to do some other tweaks to get it back to listen after I add. Not efficient I think but it is a step.
I ended up doing that:
Added Another Field in the provider (stateType: list/addedit)
Change the type per the screen I'm currently in
provider.stateType = UIStateType.add_edit;
await Navigator.push(context,
MaterialPageRoute(builder: (context) => AddEditSiteScreen()));
provider.stateType = UIStateType.list;
in build(), I check for the type
sitesProvider = Provider.of(context);
if (sitesProvider.stateType != UIStateType.add_edit) return Container();

Failed assertion: !_debugLocked is not true when using Navigator.popUntil() in Flutter

In my flutter app I use this code to go to my dashboard page, but it fails to do so the first time and I get the debugLocked error.
The launch page in the app is a Router that checks for shared preferences "sessionid" which, if set, takes the user directly to the Dashboard, else takes them to the login.
Without the below code, I get to my Dashboard just fine, using Navigator.pushReplacement() but then, a back arrow appears on the appBar. This back button takes the app back to the Router.
I searched for answers on how to remove all screens from the navigator and the following was what I found.
Navigator.of(context).popUntil(ModalRoute.withName(Dashboard.id));
Using the above code gives me the debugLocked error. Is there a solution to mitigate this problem? Or is there any other efficient way for me to remove screens from the context? Does setting automaticallyImplyLeading to false help somehow? Because this error only occurs after someone has logged in or signed up.
to remove all the previous routes use Navigator.pushAndRemoveUntil()
This can be another alternative, if you for some reason face a setState error.
navigationService.popUntil((_) => true);
navigationService.navigateTo(
'authentication',
);
basically i wait until the navigation finish setting everything and then call the navigateTo.