-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
State synchronization problem in the bloc and widget #844
Comments
Hi @don-prog 👋 Are you able to share a link to a sample app which illustrates the problem you're having? It would be much easier for me to help, thanks! |
@felangel yes, of course! Here it is: https://github.com/don-prog/flutter_cards_bloc. |
Thanks @don-prog for providing the sample! I'll take a look later today 👍 |
I took a quick look and I made a gist to illustrate how I would structure the bloc and widgets. Hope that helps! Closing for now but feel free to comment with additional questions and I'm happy to continue the conversation 👍 |
@felangel thank you very much! But what is |
@don-prog I didn't implement it because it's not relevant to bloc. You should just be able to adapt your implementation to conform to that API. |
@felangel ok, understand. And what should I do with spent cards? Should I delete them in the |
You can probably just remove them from the bloc state after the swipe 👍 |
@felangel you mean I can remove them in the |
You should remove them in the bloc state which should update the |
@felangel Please, forgive me my inquisitiveness, but I really want to correctly understand you. :) |
No problem and sorry for being unclear. I meant if (event.action == GameCardAction.delete) {
// do something
} Since Hope that helps 👍 |
@felangel I understand you, thanks! Today I'll try your suggestions a bit later. |
@felangel unfortunately, I think the problem is not solved.
But there is a delay between sending and receiving the state, so during the sending the As I understand, the animation is constantly rebuilding the widget while it removes the card. That is why the delay, which I specifically added, added and removed the problem with the different values. If you want more details I think it will be better for you to check my original code. This is directly related to the behavior of the Regards! |
@felangel I understand that you don't have enough time, so in my previous comment I tried to describe my problem more specifically. If you don't understand something in my comment, please ask questions. |
@don-prog are you able to join the bloc discord and message me so we can set up a time to do a live code share? Thanks! |
@felangel If you want, we can do this, but I shared the full problem project and described my problem. English isn't my native language. and I will descibe the same things and show the same code, but a little slower :D |
I'm trying to implement these swipeable cards(Gesture detector and Alignment type) with
bloc
. Now each card has only one number for testing.Each card deck has 10 cards and when deck has less than three cards, I emulate loading more new cards from server in the
game_bloc.dart
. When I just emulate it without delay - all fine, but when I useawait Future.delayed()
for emulating server delay there is a problem: I swipe top card(e.g. with number 7) before new pagination, during animation middle card(number 8) going to the top position with correct number, but when animation is finished I get new top card with the number 7 instead of number 8.So, I think the problem in the bloc state synchronization in the bloc class and page class, because I didn't get this problem without delay, get this problem with delay 100ms, and again didn't get this with delay 1000ms.
I’ve been trying to fix this for a long time, so your help is very necessary, any advice on how to do it correctly will be very valuable!
P.S. Most of the code is related to animation, so don't be scared of a lot of it :)
Regards.
game_state.dart:
game_bloc.dart:
game_page.dart:
The text was updated successfully, but these errors were encountered: