I am learning flutter_bloc and now i am aware now about it.I know how it used when fetching some data from server and then showing in widgets let's suppose list of items.
But i want to know how can i show loading indicator while making API call which is simple like increment quantity of item in cart.
I means it should work something like this.You click a icon and it calls a function which increment quantity of the item by an API call.
Now in that i want to fire event to ApiBloc which change it state to loading true and after the API call is done ApiBloc will change state to loading false.
And in my screen when loadimg is true i want to show the Loading indicator and as the bloc changes loading to false then Loading indicator will be disappread.
Please help me with this.
Related
I am successfully able to call the API function during pull to refresh action.
I also understand the insertitem and removeitem function on AnimatedList using global key
but I am having a hard time looking for references wherein the refresh indicator and animated list are combined.
If you could share a clue on what to use for the AnimatedList so that it gets updated or rebuild the list, that would be enough for me to handle the rest.
What I do is fetching items from Firebase then saving them in a list and then I display them in a ListView. The Problem that I have now is that I check if the list has Items and if so it displays my ListView with the Items and if there are no items it displays a Text but even but even if there are items the text gets displayed but after pressing hot reload the items get shown.
My guess was that there is a Problem with the State of the Widgets overall because stuff like SetState has no effect or a Refresh Indicator
Is there a reason why the StreamBuilder is following your masterListStart().asStream as opposed to the masterList stream? I'm not saying it's wrong, its just not immediately obvious.
Either way, it's not rebuilding automatically because the only part of your displayStory method that is reactive to the stream doesn't get built until after the non empty list condition is met. Without implementing a reactive state management solution there's nothing in your code that automatically notifies any listeners that the state of the storysList has changed, which means nothing is triggering a rebuild. Which is why you have to hot reload to see the changes.
Without me getting too deep into your code, try returning the StreamBuilder at the top level of the displayStory method and putting all the conditionals inside its its builder method.
Hi I'm trying to use ShowModalBottomSheet in my flutter App. But right now how it's being worked is the data which need to be displayed is being fetched only when ShowModalBottomSheet code executed and which creating a delay.
I want to know how do I prefetch the data beforhand using Future so that which can be used instantly when ShowModalBottomSheet triggered.
You could use and create a provider or bloc, and load the data, whenever the application's starts or the page is opened.
This way, the data will be available before the bottom sheet opens.
Pardon me if this is a naive question but I am trying to figure out a way in Flutter to load different data when the user clicks a button. The way I currently see is routing the user to a new screen everytime but I am sure there would be a better approach without loading the whole screen everytime
You should use a Stateful Widget
I would create a Future Builder / ListView Builder. Depending on how you want it to behave you could have the ListView items clear before regenerating the list of items to show.
Future Builder you could create a function to return certain widgets depending on the request you make with the function.
I have a page that presents chat messages and has the dates of a group of messages as a divider in my flutter app. The data is pulled from localDB and I am trying to make it refresh the data by polling the DB for updates, however everytime I rebuild the stream or even future it makes the screen flicker and it automatically scrolls to the top of the list. The code is too big for here so I have posted it here.
It uses a Stream builder that calls a widget with data it gets from the first stream and uses another streambuilder to build the messages. I am sure this has something to do with it, but have no idea how to change that or fix the flicker and scroll weirdness.
Hoping someone has some ideas of how to handle this better or fix the flickering.
What you could try is creating a "app state" for each page, for example:
Loading app state - which displays a Progress Indicator when you're polling from DB/server.
Success app state - this dismisses the Progress Indicator and just shows an empty container, displaying your data.
Failed app state - Displays an error icon of your choice.
Perhaps you could try this library, Flutter GetX , and I recommend this library because of how simple it is to use.
It has state management library, which saved me lots of time and code using streams and setState({}).