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

PageController stateprovider doesn't work when .previousPage() or nextPage() is pressed #3569

Open
mohadel92 opened this issue May 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working needs triage

Comments

@mohadel92
Copy link

using a simple stateprovider the .nextPage(..) method or .previousPage(..) doesn't work

AutoDisposeStateProvider<PageController> _pageControllerProvider =
    StateProvider.autoDispose<PageController>(
        (StateProviderRef<PageController> ref) {
  return PageController(
    initialPage: 0,
    viewportFraction: 0.9,
  );
});

my code: 
PageView.builder(
                            allowImplicitScrolling: true,
                            controller:
                                ref.watch(_pageControllerProvider),
                            itemCount: response?.length ?? 0,
                            itemBuilder: (BuildContext context, int index) {
                      
                              return Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: MyWidget()
                              );
                            },
                          ),

 press handler:

Consumer(builder:
                              (BuildContext context, WidgetRef ref, _) {
                            return PrevNextRow(
                              onNextPressed: () async {
                                ref
                                    .read(
                                        _pageControllerProvider)
                                    .nextPage(
                                        duration: const Duration(
                                          milliseconds: 500,
                                        ),
                                        curve: Curves.decelerate);
                              },
                              onPrevPressed: () async {
  ref
                                    .read(
                                        _pageControllerProvider)
                                    .previousPage(
                                        duration: const Duration(
                                          milliseconds: 500,
                                        ),
                                        curve: Curves.decelerate);
},
                            );
                          })


Expected behavior
PageController should move the list to the next item

@mohadel92 mohadel92 added bug Something isn't working needs triage labels May 22, 2024
@b2nkuu
Copy link

b2nkuu commented Jun 24, 2024

Hi, mohadel92
In my opinion,
Maybe you use StateProvider is wrong concept.
Class is must to has immutable.
PageController is not immutable class is cannot use in state.

This hope you help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants