How to change AppBar Title according to the appearance of ListView item, I used inview_notifier_list to check the appearance of item but when placing inview_notifier_list inside SingleChildScrollView it works incorrectly
InViewList only works if you let it use its own ScrollController. If you would like to show a ImageSlideshow at the top of the list, you can do so by adding it to the top of the list like this:
InViewNotifierList(
isInViewPortCondition: (double deltaTop, double deltaBottom, double vpHeight) {
return deltaTop < 20 && deltaBottom > 20;
},
// count of your items + 1
itemCount: 10 + 1,
builder: (context, i) {
// Return the ImageSlideshow if it's the first item
if (i == 0) {
return Padding(
padding: const EdgeInsets.all(10),
child: ImageSlideshow(
width: double.infinity,
height: 200,
initialPage: 0,
indicatorColor: Colors.blue,
indicatorBackgroundColor: Colors.grey,
autoPlayInterval: 3000,
isLoop: true,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(color: Colors.red),
),
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(color: Colors.blue),
),
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(color: Colors.orange),
),
],
),
);
}
// Make up for increasing the itemCount by 1 by decrementing i
i--;
return InViewNotifierWidget(
id: '$i',
builder: (context, isInView, child) {
if (isInView) {
WidgetsBinding.instance.addPostFrameCallback((_) {
yourMethodToUpdateTitleWithIndex(i);
});
}
return Padding(
padding: const EdgeInsets.only(bottom: 50.0),
child: Container(
width: 100,
height: 100,
color: Colors.red,
child: Center(
child: Text("Item $i"),
)),
);
},
);
},
)
BTW: The code is tested and fully functional.
Feel free to reach out if you need any more help with implementing the solution 🙂
2
Answers
Here is my code:
InViewList
only works if you let it use its ownScrollController
. If you would like to show aImageSlideshow
at the top of the list, you can do so by adding it to the top of the list like this:BTW: The code is tested and fully functional.
Feel free to reach out if you need any more help with implementing the solution 🙂