Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support all ListView and CustomScrollView properties #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A Flutter package that builds a [ListView](https://api.flutter.dev/flutter/widgets/ListView-class.html) or [CustomScrollView](https://api.flutter.dev/flutter/widgets/CustomScrollView-class.html) and notifies when the widgets are on screen within a provided area.

| Example 1 | Example 2 | Example 3(Auto-play video) |
| :------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------: |
|:--------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------:|
| ![ezgif com-gif-maker (1)](https://user-images.githubusercontent.com/31307345/59602739-2f022d00-9125-11e9-84ef-19a33f8bd782.gif) | ![ezgif com-video-to-gif (1)](https://user-images.githubusercontent.com/31307345/59602740-2f022d00-9125-11e9-8ee6-044e44f6048f.gif) | ![ezgif com-video-to-gif (2)](https://user-images.githubusercontent.com/31307345/59602744-2f9ac380-9125-11e9-8a8f-7e68bdc27c16.gif) |
| **Example 4(Custom Scroll View)** | | |
| ![csv_example](https://user-images.githubusercontent.com/31307345/78342587-22b56680-75b7-11ea-8f6e-22a8f378546d.gif) | | |
Expand Down Expand Up @@ -51,7 +51,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: InViewNotifierList(
...
/// ...
),
);
}
Expand Down
74 changes: 74 additions & 0 deletions lib/src/inview_notifier_list.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:inview_notifier_list/src/inview_notifier.dart';

import 'inherited_inview_widget.dart';
Expand All @@ -11,6 +13,7 @@ import 'inview_state.dart';
class InViewNotifierList extends InViewNotifier {
InViewNotifierList({
Key? key,
Key? listViewBuilderKey,
int? itemCount,
required IndexedWidgetBuilder builder,
List<String> initialInViewIds = const [],
Expand All @@ -26,6 +29,19 @@ class InViewNotifierList extends InViewNotifier {
bool? primary,
bool shrinkWrap = false,
bool addAutomaticKeepAlives = true,
double? itemExtent,
ItemExtentBuilder? itemExtentBuilder,
Widget? prototypeItem,
int? Function(Key)? findChildIndexCallback,
bool addRepaintBoundaries = true,
bool addSemanticIndexes = true,
double? cacheExtent,
int? semanticChildCount,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior =
ScrollViewKeyboardDismissBehavior.manual,
String? restorationId,
Clip clipBehavior = Clip.hardEdge,
}) : assert(endNotificationOffset >= 0.0),
super(
key: key,
Expand All @@ -35,16 +51,29 @@ class InViewNotifierList extends InViewNotifier {
throttleDuration: throttleDuration,
isInViewPortCondition: isInViewPortCondition,
child: ListView.builder(
key: listViewBuilderKey,
padding: padding,
controller: controller,
scrollDirection: scrollDirection,
physics: physics,
reverse: reverse,
primary: primary,
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
addSemanticIndexes: addSemanticIndexes,
shrinkWrap: shrinkWrap,
itemCount: itemCount,
itemBuilder: builder,
itemExtent: itemExtent,
itemExtentBuilder: itemExtentBuilder,
cacheExtent: cacheExtent,
semanticChildCount: semanticChildCount,
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior,
restorationId: restorationId,
clipBehavior: clipBehavior,
findChildIndexCallback: findChildIndexCallback,
prototypeItem: prototypeItem,
),
);

Expand All @@ -56,6 +85,34 @@ class InViewNotifierList extends InViewNotifier {
}
}

class InViewNotifierListCustom extends InViewNotifier {
InViewNotifierListCustom({
Key? key,
List<String> initialInViewIds = const [],
double endNotificationOffset = 0.0,
VoidCallback? onListEndReached,
Duration throttleDuration = const Duration(milliseconds: 200),
required IsInViewPortCondition isInViewPortCondition,
required ListView listViewCustom,
}) : assert(endNotificationOffset >= 0.0),
super(
key: key,
initialInViewIds: initialInViewIds,
endNotificationOffset: endNotificationOffset,
onListEndReached: onListEndReached,
throttleDuration: throttleDuration,
isInViewPortCondition: isInViewPortCondition,
child: listViewCustom,
);

static InViewState? of(BuildContext context) {
final InheritedInViewWidget widget = context
.getElementForInheritedWidgetOfExactType<InheritedInViewWidget>()!
.widget as InheritedInViewWidget;
return widget.inViewState;
}
}

///builds a [CustomScrollView] and notifies when the widgets are on screen within a provided area.
///
///A [CustomScrollView] lets you supply [slivers] directly to create various scrolling effects,
Expand All @@ -80,6 +137,15 @@ class InViewNotifierCustomScrollView extends InViewNotifier {
bool shrinkWrap = false,
Key? center,
double anchor = 0.0,
Key? customScrollViewKey,
ScrollBehavior? scrollBehavior,
double? cacheExtent,
int? semanticChildCount,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior =
ScrollViewKeyboardDismissBehavior.manual,
String? restorationId,
Clip clipBehavior = Clip.hardEdge,
}) : super(
key: key,
initialInViewIds: initialInViewIds,
Expand All @@ -88,6 +154,7 @@ class InViewNotifierCustomScrollView extends InViewNotifier {
throttleDuration: throttleDuration,
isInViewPortCondition: isInViewPortCondition,
child: CustomScrollView(
key: customScrollViewKey,
slivers: slivers,
anchor: anchor,
controller: controller,
Expand All @@ -97,6 +164,13 @@ class InViewNotifierCustomScrollView extends InViewNotifier {
primary: primary,
shrinkWrap: shrinkWrap,
center: center,
keyboardDismissBehavior: keyboardDismissBehavior,
dragStartBehavior: dragStartBehavior,
restorationId: restorationId,
cacheExtent: cacheExtent,
semanticChildCount: semanticChildCount,
clipBehavior: clipBehavior,
scrollBehavior: scrollBehavior,
),
);

Expand Down
Loading