Skip to content
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

PageSwipe/Change not working (animation + logic) + SDK Requirements #23

Closed
LidorPrototype opened this issue Aug 6, 2022 · 3 comments
Closed

Comments

@LidorPrototype
Copy link

PageSwipe not working (animation + logic)

After I run it, I either swipe right or press the continue button in order to move between the first registry screens, but the animation of the arrow circle does not work (it stays on the first image like), the swipe work on the body image with the person and the texts, but when i get to the last one nothing happened.

On every swipe I do there I get the following error:

Bad state: add(PageSwipedEvent) was called without a registered event handler.
Make sure to register a handler via on<PageSwipedEvent>((event, emit) {...})

following the stack trace I can see it was originated here (onboarding_content.dart):

onPageChanged: (index) {
  bloc.add(PageSwipedEvent(index: index));
},

SDK Requirements

first of all in order for it to run I had to change the following
minSdkVersion 18
and
compileSdkVersion 33


@LidorPrototype LidorPrototype changed the title PageSwipe not working (animation + logic) + SDK Requirements PageSwipe/Change not working (animation + logic) + SDK Requirements Aug 7, 2022
@LidorPrototype
Copy link
Author

The problem is mainly with the verion of BloC, now the version is 8.0.0, at time of this project the version was much lower, a lot of changes has been since.

I was on the right way with on<PageSwipedEvent>((event, emit) => mapEventToState(event));, but I tried to mix two versions here, The mapEventToState() method uses yield instead of on<Event>((event, emit) => emit(State)).
This was changed in BLoC 8.0.0 (changelog), since adding on<PageChangedEvent>((event, emit) => mapEventToState(event)); fixed the error but the code didnt do what I wanted still that what made me think that it might be part of the solution.

Working code (migrating from yield to on<Event>((event, emit) => emit(State)) and moving the on handlers inside the constructor):

class OnboardingBloc extends Bloc<OnboardingEvent, OnboardingState> {

  int pageIndex = 0;
  final pageController = PageController(initialPage: 0);

  OnboardingBloc() : super(OnboardingInitial()){

    on<PageChangedEvent>((event, emit) async {
    
        if (pageIndex == 2) {
            emit(NextScreenState());
            return;
          }
          pageIndex += 1;
        
          pageController.animateToPage(
            pageIndex,
            duration: Duration(milliseconds: 500),
            curve: Curves.ease,
          );
        emit(PageChangedState(counter: pageIndex));
    
    });

    on<PageSwipedEvent>((event, emit) async {
       pageIndex = event.index;
       emit(PageChangedState(counter: pageIndex));
    });

}

@LidorPrototype
Copy link
Author

Also need to change all of the BloC files accordingly

@wachichow38
Copy link

Hello! Does the code run well on your computer? Can you please help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants