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;
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
add a comment |
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
add a comment |
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
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
dart
asked Mar 27 at 16:19
RickRick
13110 bronze badges
13110 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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");
add a comment |
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
)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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");
add a comment |
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");
add a comment |
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");
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");
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
add a comment |
add a comment |
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
)
add a comment |
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
)
add a comment |
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
)
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
)
answered Mar 27 at 16:58
divyanshu bhargavadivyanshu bhargava
3941 silver badge15 bronze badges
3941 silver badge15 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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