How to get from index in PageView onPageChanged in Flutter?Pageview implementationmap_view => NoSuchMethodError flutterFlutter - Save Interaction or State When Switching TabsNesting PageViews in flutterFlutter change CupertinoTabBar background color dynamicallyFlutter Switching FAB on PageView Pages with animation in ScaffoldDynamically build a Flutter PageViewIs there a way to create an AlertDialog with PageView in Flutter?How to use a Pagview PageController in Flutter using Redux

Why "multi-band antenna", not "multi-bands antenna"?

Mathematical uses of string theory

Is “I am getting married with my sister” ambiguous?

Vacuum collapse -- why do strong metals implode but glass doesn't?

Church Booleans

Bankers with rancor

Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")

Infinitely long proofs

Can you feel passing through the sound barrier in an F-16?

What magic extends life or grants immortality?

Was Switzerland really impossible to invade during WW2?

What is the appropriate benchmark for a Long/Short VIX futures strategy?

Would it be possible to have a GMO that produces chocolate?

Sun setting in East!

Avoiding racist tropes in fantasy

Can a PC's alignment be forcibly changed?

Does an object count as "being moved" when placed in a Bag of Holding before its wielder moves, and then after moving they take the object out again?

Why did this happen to Thanos's ships at the end of "Avengers: Endgame"?

Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?

Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?

How can I watch the 17th (or last, if less) line in files of a folder?

How big would a Daddy Longlegs Spider need to be to kill an average Human?

Is it safe to remove the bottom chords of a series of garage roof trusses?

In an emergency, how do I find and share my position?



How to get from index in PageView onPageChanged in Flutter?


Pageview implementationmap_view => NoSuchMethodError flutterFlutter - Save Interaction or State When Switching TabsNesting PageViews in flutterFlutter change CupertinoTabBar background color dynamicallyFlutter Switching FAB on PageView Pages with animation in ScaffoldDynamically build a Flutter PageViewIs there a way to create an AlertDialog with PageView in Flutter?How to use a Pagview PageController in Flutter using Redux






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















How do I get the previous index in PageView onPageChanged? Currently, I can get the current index when the page changes with the following code:



PageView(
children: <Widget>[
SomeView(),
SomeOtherViews(),
SomeOtherViews(),
],
controller: _pageViewController,
onPageChanged: _onPageViewChange,
);

_onPageViewChange(int page)
print("Current Page: " + page.toString());



Does flutter have any built-in function for this? Or should I just manually save the page as reference for the previous page?



  • Yes I have thought of that, I just want to know if there's a faster way without having to create a variable









share|improve this question






























    0















    How do I get the previous index in PageView onPageChanged? Currently, I can get the current index when the page changes with the following code:



    PageView(
    children: <Widget>[
    SomeView(),
    SomeOtherViews(),
    SomeOtherViews(),
    ],
    controller: _pageViewController,
    onPageChanged: _onPageViewChange,
    );

    _onPageViewChange(int page)
    print("Current Page: " + page.toString());



    Does flutter have any built-in function for this? Or should I just manually save the page as reference for the previous page?



    • Yes I have thought of that, I just want to know if there's a faster way without having to create a variable









    share|improve this question


























      0












      0








      0








      How do I get the previous index in PageView onPageChanged? Currently, I can get the current index when the page changes with the following code:



      PageView(
      children: <Widget>[
      SomeView(),
      SomeOtherViews(),
      SomeOtherViews(),
      ],
      controller: _pageViewController,
      onPageChanged: _onPageViewChange,
      );

      _onPageViewChange(int page)
      print("Current Page: " + page.toString());



      Does flutter have any built-in function for this? Or should I just manually save the page as reference for the previous page?



      • Yes I have thought of that, I just want to know if there's a faster way without having to create a variable









      share|improve this question














      How do I get the previous index in PageView onPageChanged? Currently, I can get the current index when the page changes with the following code:



      PageView(
      children: <Widget>[
      SomeView(),
      SomeOtherViews(),
      SomeOtherViews(),
      ],
      controller: _pageViewController,
      onPageChanged: _onPageViewChange,
      );

      _onPageViewChange(int page)
      print("Current Page: " + page.toString());



      Does flutter have any built-in function for this? Or should I just manually save the page as reference for the previous page?



      • Yes I have thought of that, I just want to know if there's a faster way without having to create a variable






      dart flutter pageviews






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 16:19









      RickRick

      13110 bronze badges




      13110 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          1













          Decrement page by 1 and store in a class Variable (call setState & modify) or local variable. If current-page is 0 set previousPage to totalPageCount - 1.



          _onPageViewChange(int page) 
          print("Current Page: " + page.toString());
          int previousPage = page;
          if(page != 0) previousPage--;
          else previousPage = 2;
          print("Previous page: $previousPage");






          share|improve this answer


































            0













            You can use PageView.builder, it will give you page index.



            PageView.builder(
            itemBuilder: (context, index)
            // index gives you current page position.
            return _buildPage();
            ,
            itemCount: listItemCount, // Can be null
            )





            share|improve this answer



























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381980%2fhow-to-get-from-index-in-pageview-onpagechanged-in-flutter%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1













              Decrement page by 1 and store in a class Variable (call setState & modify) or local variable. If current-page is 0 set previousPage to totalPageCount - 1.



              _onPageViewChange(int page) 
              print("Current Page: " + page.toString());
              int previousPage = page;
              if(page != 0) previousPage--;
              else previousPage = 2;
              print("Previous page: $previousPage");






              share|improve this answer































                1













                Decrement page by 1 and store in a class Variable (call setState & modify) or local variable. If current-page is 0 set previousPage to totalPageCount - 1.



                _onPageViewChange(int page) 
                print("Current Page: " + page.toString());
                int previousPage = page;
                if(page != 0) previousPage--;
                else previousPage = 2;
                print("Previous page: $previousPage");






                share|improve this answer





























                  1












                  1








                  1







                  Decrement page by 1 and store in a class Variable (call setState & modify) or local variable. If current-page is 0 set previousPage to totalPageCount - 1.



                  _onPageViewChange(int page) 
                  print("Current Page: " + page.toString());
                  int previousPage = page;
                  if(page != 0) previousPage--;
                  else previousPage = 2;
                  print("Previous page: $previousPage");






                  share|improve this answer















                  Decrement page by 1 and store in a class Variable (call setState & modify) or local variable. If current-page is 0 set previousPage to totalPageCount - 1.



                  _onPageViewChange(int page) 
                  print("Current Page: " + page.toString());
                  int previousPage = page;
                  if(page != 0) previousPage--;
                  else previousPage = 2;
                  print("Previous page: $previousPage");







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 27 at 16:51

























                  answered Mar 27 at 16:45









                  Tirth PatelTirth Patel

                  1,1782 gold badges12 silver badges27 bronze badges




                  1,1782 gold badges12 silver badges27 bronze badges


























                      0













                      You can use PageView.builder, it will give you page index.



                      PageView.builder(
                      itemBuilder: (context, index)
                      // index gives you current page position.
                      return _buildPage();
                      ,
                      itemCount: listItemCount, // Can be null
                      )





                      share|improve this answer





























                        0













                        You can use PageView.builder, it will give you page index.



                        PageView.builder(
                        itemBuilder: (context, index)
                        // index gives you current page position.
                        return _buildPage();
                        ,
                        itemCount: listItemCount, // Can be null
                        )





                        share|improve this answer



























                          0












                          0








                          0







                          You can use PageView.builder, it will give you page index.



                          PageView.builder(
                          itemBuilder: (context, index)
                          // index gives you current page position.
                          return _buildPage();
                          ,
                          itemCount: listItemCount, // Can be null
                          )





                          share|improve this answer













                          You can use PageView.builder, it will give you page index.



                          PageView.builder(
                          itemBuilder: (context, index)
                          // index gives you current page position.
                          return _buildPage();
                          ,
                          itemCount: listItemCount, // Can be null
                          )






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 27 at 16:58









                          divyanshu bhargavadivyanshu bhargava

                          3941 silver badge15 bronze badges




                          3941 silver badge15 bronze badges






























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381980%2fhow-to-get-from-index-in-pageview-onpagechanged-in-flutter%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown