New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streambuilder not rebuilding after BLOC event while using Built value #1707
Comments
Hi @MatthewCoetzee412 👋 I'm guessing the issue is the related to the fact the new state being emitted is considered equal to the previous state as described by the FAQs. Are you able to share a link to a sample app which illustrates the issue? It would be much easier for me to help/provide suggestions if I am able to reproduce/debug the issue locally, thanks! 👍 |
Hi Felangel, thank you for the swift response! I attempted to make a mock of my app to reproduce the problem but the problem comes from the Streambuilder not refreshing with the updated Firestore data after a BLOC event which I couldn't model accurately enough to reproduce the problem, so I would have to make an app using Firebase. I will post the link tomorrow to the repository, thanks for your help! |
Hi Falangel, Below is a replication of the problem: If you add a Food item, the Streambuilder does not update itself. Any help would be appreciated! |
Hi @MatthewCoetzee412 👋
Hope this gives you a couple of ideas ✌ |
Hi @RollyPeres and @felangel , thank you so much for the advice! 🙏 💯 I have switched from built_value to freezed and its made it a lot easier to implement everything I need too plus much less boiler plate. I also toke your advice for handling errors in Streams and I am using the dartz package now which makes it really easy and lastly I removed the Pipe Layer completely. I have managed to implement everything but I just have one caveat which I'm not sure how to fix, which is the Food Items are not updating once I add an Item after I have scroll down and fetched more results. I don't mind closing the issue and I don't want to waste your time but if you wouldn't mind taking a look at the updated repository and provide any suggestions perhaps on how to fix it I would appreciate it a lot. Any help would be appreciated but I don't mind closing and figuring it out for myself. Repo Link: My thanks again!
|
I've opened a PR with some minor updates mostly related to updating bloc to latest version. The problem you're facing is called firestore live pagination 🤦♂️ |
Thanks @RollyPeres 🙏 🙏 🙏 , Really, genuinely , appreciate all the help, thank you very much! Kind Regards |
Hi, for anyone in the future wanting to know how to fix the problem of realtime pagination as metioned above, Below is the solution: class FoodLoadBloc extends Bloc<FoodLoadEvent, FoodLoadState> {
final FirebaseRepository _repository;
FoodLoadBloc(this._repository);
//Create a list of stream subscriptions
List<StreamSubscription> _subscriptions = [];
@override
FoodLoadState get initialState => FoodLoadState.intial();
@override
Stream<FoodLoadState> mapEventToState(FoodLoadEvent event) async* {
yield* event.map(load: (_) async* {
StreamSubscription<Either<ItemFailure, List<Food>>> _streamSubscription =
_repository.getMoreItems(_.items, _.documentSnapshot).listen(
(foodItems) => add(FoodLoadEvent.itemRecieved(foodItems)));
//Add a new stream subscription to the list each time the event is called
_subscriptions.add(_streamSubscription);
}, itemRecieved: (event) async* {
yield event.items
.fold((l) => FoodLoadState.error(l), (r) => FoodLoadState.success(r));
});
}
@override
Future<void> close() {
//Lastly, dispose the stream subscriptions
for (StreamSubscription sub in _subscriptions) sub.cancel();
return super.close();
}
} Hope that helps someone!
|
I am trying to implement pagination in my application but I have not been successful in doing so.
I am using Firebase, specifically Firestore with the BLOC pattern alongside Built Value which I started using recently to make pagination easier.
I would really appreciate any help or referral links how to use these technologies together.
My application architecture is as follows:
https://i.stack.imgur.com/MgNjx.png
I have tried to keep to the BLOC pattern as much as possible but this in turn has made it really difficult to paginate largely ,because of using built value as built value make it really difficult to use Streams and Futures. I have looked all over the Internet but I could not find any tutorial or docs to use built value with Firestore and BLOC specifically to paginate.
The problem is that when I do any of the CRUD functions for example delete an Category from a list, the Stream Builder is not updating the list despite the pagination and everything else working.
Currently I have tried using the a Listview builder by itself which obviously didn't work at all,so I moved to a Stream Builder and tryed both Streams and Futures(.asStream) but it is not updating.
Below is some of the code:
The model:
The query:
The BLOC:
The state:
The event:
The pagination screen(Contained inside a stateful widget):
Thank you for you time and sorry for being so verbose
-Matt
The text was updated successfully, but these errors were encountered: