Skip to content

Commit

Permalink
removed contextCacheCount property
Browse files Browse the repository at this point in the history
  • Loading branch information
vamsi-kleargroup committed Dec 28, 2021
1 parent 2a2752b commit ec8ee3d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 22 deletions.
1 change: 0 additions & 1 deletion example/lib/csv_example.dart
Expand Up @@ -22,7 +22,6 @@ class CSVExample extends StatelessWidget {
InViewNotifierCustomScrollView(
initialInViewIds: ['grid3', 'grid4', 'grid5'],
isInViewPortCondition: condition,
contextCacheCount: 35,
controller: scrollController,
slivers: <Widget>[
SliverPadding(
Expand Down
13 changes: 1 addition & 12 deletions lib/src/inview_notifier.dart
Expand Up @@ -16,11 +16,6 @@ class InViewNotifier extends StatefulWidget {
///The widget that should be displayed in the [InViewNotifier].
final ScrollView child;

///The number of widget's contexts the InViewNotifier should stored/cached for
///the calculations thats needed to be done to check if the widgets are inView or not.
///Defaults to 10 and should be greater than 1. This is done to reduce the number of calculations being performed.
final int contextCacheCount;

///The distance from the bottom of the list where the [onListEndReached] should be invoked.
final double endNotificationOffset;

Expand All @@ -43,13 +38,11 @@ class InViewNotifier extends StatefulWidget {
Key? key,
required this.child,
this.initialInViewIds = const [],
this.contextCacheCount = 10,
this.endNotificationOffset = 0.0,
this.onListEndReached,
this.throttleDuration = const Duration(milliseconds: 200),
required this.isInViewPortCondition,
}) : assert(contextCacheCount >= 1),
assert(endNotificationOffset >= 0.0),
}) : assert(endNotificationOffset >= 0.0),
scrollDirection = child.scrollDirection,
super(key: key);

Expand Down Expand Up @@ -139,10 +132,6 @@ class _InViewNotifierState extends State<InViewNotifier> {
//when user is not scrolling
if (notification is UserScrollNotification &&
notification.direction == ScrollDirection.idle) {
//Keeps only the last number contexts provided by user. This prevents overcalculation
//by iterating over non visible widget contexts in scroll listener
_inViewState!.removeContexts(widget.contextCacheCount);

if (!_streamController!.isClosed && isScrollDirection) {
_streamController!.add(notification);
}
Expand Down
7 changes: 1 addition & 6 deletions lib/src/inview_notifier_list.dart
Expand Up @@ -14,7 +14,6 @@ class InViewNotifierList extends InViewNotifier {
int? itemCount,
required IndexedWidgetBuilder builder,
List<String> initialInViewIds = const [],
int contextCacheCount = 10,
double endNotificationOffset = 0.0,
VoidCallback? onListEndReached,
Duration throttleDuration = const Duration(milliseconds: 200),
Expand All @@ -27,15 +26,13 @@ class InViewNotifierList extends InViewNotifier {
bool? primary,
bool shrinkWrap = false,
bool addAutomaticKeepAlives = true,
}) : assert(contextCacheCount >= 1),
assert(endNotificationOffset >= 0.0),
}) : assert(endNotificationOffset >= 0.0),
super(
key: key,
initialInViewIds: initialInViewIds,
endNotificationOffset: endNotificationOffset,
onListEndReached: onListEndReached,
throttleDuration: throttleDuration,
contextCacheCount: contextCacheCount,
isInViewPortCondition: isInViewPortCondition,
child: ListView.builder(
padding: padding,
Expand Down Expand Up @@ -71,7 +68,6 @@ class InViewNotifierCustomScrollView extends InViewNotifier {
Key? key,
required List<Widget> slivers,
List<String> initialInViewIds = const [],
int contextCacheCount = 10,
double endNotificationOffset = 0.0,
VoidCallback? onListEndReached,
Duration throttleDuration = const Duration(milliseconds: 200),
Expand All @@ -90,7 +86,6 @@ class InViewNotifierCustomScrollView extends InViewNotifier {
endNotificationOffset: endNotificationOffset,
onListEndReached: onListEndReached,
throttleDuration: throttleDuration,
contextCacheCount: contextCacheCount,
isInViewPortCondition: isInViewPortCondition,
child: CustomScrollView(
slivers: slivers,
Expand Down
3 changes: 0 additions & 3 deletions lib/src/inview_state.dart
Expand Up @@ -39,9 +39,6 @@ class InViewState extends ChangeNotifier {
_contexts.removeWhere((d) => d.context == context);
}

///Keeps the number of widget's contexts the InViewNotifier should stored/cached for
///the calculations thats needed to be done to check if the widgets are inView or not.
///Defaults to 10 and should be greater than 1. This is done to reduce the number of calculations being performed.
void removeContexts(int letRemain) {
if (_contexts.length > letRemain) {
_contexts = _contexts.skip(_contexts.length - letRemain).toSet();
Expand Down

0 comments on commit ec8ee3d

Please sign in to comment.