Make itemBuilder run every time without calling setState()
up vote
0
down vote
favorite
I am having a code like this for PageView.builder
@override
Widget build(BuildContext context)
return PageView.builder(
itemCount: myList.length,
onPageChanged: (int pageIndex) => setState(() => index = pageIndex), // this make it work fine
itemBuilder: (context, index) => MyPage(myList[index])
);
The problem with this itemBuilder
(of PageView.builder
) and normal itemBuilder
(of ListView.builder
) is that they stop getting called once they have drawn the widget on the screen for previous index
value.
Now in my use case, I want this itemBuilder
to fire every time the Page has changed in the PageView
because I am updating list
and now I want to show new data in MyPage for new list
. How to do that?
PS: There is onPageChanged()
callback and I can use setState()
in that, it works fine but it simply ruins the purpose of PageView
OR is it okay to use setState()
in onPageChanged()
, wont' that be redundant?
dart flutter
add a comment |
up vote
0
down vote
favorite
I am having a code like this for PageView.builder
@override
Widget build(BuildContext context)
return PageView.builder(
itemCount: myList.length,
onPageChanged: (int pageIndex) => setState(() => index = pageIndex), // this make it work fine
itemBuilder: (context, index) => MyPage(myList[index])
);
The problem with this itemBuilder
(of PageView.builder
) and normal itemBuilder
(of ListView.builder
) is that they stop getting called once they have drawn the widget on the screen for previous index
value.
Now in my use case, I want this itemBuilder
to fire every time the Page has changed in the PageView
because I am updating list
and now I want to show new data in MyPage for new list
. How to do that?
PS: There is onPageChanged()
callback and I can use setState()
in that, it works fine but it simply ruins the purpose of PageView
OR is it okay to use setState()
in onPageChanged()
, wont' that be redundant?
dart flutter
so you have to rebuild yourPageView
as there is no "animated" alternative likeAnimatedList
for staticListView
– pskink
Nov 17 at 9:31
So, I ended up calling setState() to solve the issue. Not a nice solution but worked for me.
– Volley Ball
Nov 17 at 9:33
you dont have to use anyonPageChanged
and callsetState
- just make surePageView
is rebuilt - like here
– pskink
Nov 17 at 9:38
@pskink I am sorry, I didn't quite try it yet, I am still using my solution of callingsetState()
fromonPageChanged()
.
– Volley Ball
Nov 17 at 11:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am having a code like this for PageView.builder
@override
Widget build(BuildContext context)
return PageView.builder(
itemCount: myList.length,
onPageChanged: (int pageIndex) => setState(() => index = pageIndex), // this make it work fine
itemBuilder: (context, index) => MyPage(myList[index])
);
The problem with this itemBuilder
(of PageView.builder
) and normal itemBuilder
(of ListView.builder
) is that they stop getting called once they have drawn the widget on the screen for previous index
value.
Now in my use case, I want this itemBuilder
to fire every time the Page has changed in the PageView
because I am updating list
and now I want to show new data in MyPage for new list
. How to do that?
PS: There is onPageChanged()
callback and I can use setState()
in that, it works fine but it simply ruins the purpose of PageView
OR is it okay to use setState()
in onPageChanged()
, wont' that be redundant?
dart flutter
I am having a code like this for PageView.builder
@override
Widget build(BuildContext context)
return PageView.builder(
itemCount: myList.length,
onPageChanged: (int pageIndex) => setState(() => index = pageIndex), // this make it work fine
itemBuilder: (context, index) => MyPage(myList[index])
);
The problem with this itemBuilder
(of PageView.builder
) and normal itemBuilder
(of ListView.builder
) is that they stop getting called once they have drawn the widget on the screen for previous index
value.
Now in my use case, I want this itemBuilder
to fire every time the Page has changed in the PageView
because I am updating list
and now I want to show new data in MyPage for new list
. How to do that?
PS: There is onPageChanged()
callback and I can use setState()
in that, it works fine but it simply ruins the purpose of PageView
OR is it okay to use setState()
in onPageChanged()
, wont' that be redundant?
dart flutter
dart flutter
edited Nov 11 at 16:47
asked Nov 11 at 16:16
Volley Ball
426214
426214
so you have to rebuild yourPageView
as there is no "animated" alternative likeAnimatedList
for staticListView
– pskink
Nov 17 at 9:31
So, I ended up calling setState() to solve the issue. Not a nice solution but worked for me.
– Volley Ball
Nov 17 at 9:33
you dont have to use anyonPageChanged
and callsetState
- just make surePageView
is rebuilt - like here
– pskink
Nov 17 at 9:38
@pskink I am sorry, I didn't quite try it yet, I am still using my solution of callingsetState()
fromonPageChanged()
.
– Volley Ball
Nov 17 at 11:47
add a comment |
so you have to rebuild yourPageView
as there is no "animated" alternative likeAnimatedList
for staticListView
– pskink
Nov 17 at 9:31
So, I ended up calling setState() to solve the issue. Not a nice solution but worked for me.
– Volley Ball
Nov 17 at 9:33
you dont have to use anyonPageChanged
and callsetState
- just make surePageView
is rebuilt - like here
– pskink
Nov 17 at 9:38
@pskink I am sorry, I didn't quite try it yet, I am still using my solution of callingsetState()
fromonPageChanged()
.
– Volley Ball
Nov 17 at 11:47
so you have to rebuild your
PageView
as there is no "animated" alternative like AnimatedList
for static ListView
– pskink
Nov 17 at 9:31
so you have to rebuild your
PageView
as there is no "animated" alternative like AnimatedList
for static ListView
– pskink
Nov 17 at 9:31
So, I ended up calling setState() to solve the issue. Not a nice solution but worked for me.
– Volley Ball
Nov 17 at 9:33
So, I ended up calling setState() to solve the issue. Not a nice solution but worked for me.
– Volley Ball
Nov 17 at 9:33
you dont have to use any
onPageChanged
and call setState
- just make sure PageView
is rebuilt - like here– pskink
Nov 17 at 9:38
you dont have to use any
onPageChanged
and call setState
- just make sure PageView
is rebuilt - like here– pskink
Nov 17 at 9:38
@pskink I am sorry, I didn't quite try it yet, I am still using my solution of calling
setState()
from onPageChanged()
.– Volley Ball
Nov 17 at 11:47
@pskink I am sorry, I didn't quite try it yet, I am still using my solution of calling
setState()
from onPageChanged()
.– Volley Ball
Nov 17 at 11:47
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53250653%2fmake-itembuilder-run-every-time-without-calling-setstate%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
so you have to rebuild your
PageView
as there is no "animated" alternative likeAnimatedList
for staticListView
– pskink
Nov 17 at 9:31
So, I ended up calling setState() to solve the issue. Not a nice solution but worked for me.
– Volley Ball
Nov 17 at 9:33
you dont have to use any
onPageChanged
and callsetState
- just make surePageView
is rebuilt - like here– pskink
Nov 17 at 9:38
@pskink I am sorry, I didn't quite try it yet, I am still using my solution of calling
setState()
fromonPageChanged()
.– Volley Ball
Nov 17 at 11:47