here is my issue, currently I have a statefulWidget and wrapped by GetBuilder, so I can listen the each widget from ListView when I scroll up and down, but now the performance is pretty low and I have no idea how to solve it.
here is the code structure:
ListView buildYear(TimelineController controller) {
return ListView.builder(
physics: BouncingScrollPhysics(),
controller: scrollController,
key: _animatedKey,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: controller.yearOld,
itemBuilder: (context, index) {
print('rendering'); // <- here I got really lots of print when I scroll up/down
return TimelineItemWidget(
controller: controller,
index: index,
);
},
);
};
Widget TimelineItemWidget({int index, TimelineController controller}) {
// here I need to test the offset of scrollController and give the bool value to Widget, to update Widget status, I dont know it it is a good idea
return Widget(...);
}
I am also listening the scrollController in initState to calculate in-time value when I am scrolling:
@override
void initState() {
super.initState();
scrollController.addListener(() {
timelineController.getActivatedIndex();
timelineController.getScrollPy();
});}
The reason that frame is so low I guess is followings:
- I am listening the ScrollController to get current offset, so I can know which widget from ListView.builder is scrolled to.(Because each widget has different height).
- Each step I am scroll screen up and down, ListView needs to calculate if the widget needs to be updated based on the value returned by scrollController.
- If I extract the widget to a statelessWidget, does it help to save performance?