Skip to content

Commit

Permalink
Merge pull request #6 from iptton/master
Browse files Browse the repository at this point in the history
solves issue #5
  • Loading branch information
rvamsikrishna authored Dec 13, 2019
2 parents 0b3fb8b + 008cad9 commit da3a9e4
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/lib/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Box extends StatelessWidget {
color: isInView ? Colors.lightGreen : Colors.amber,
child: Text(
'$id : $inViewTxt',
key: ValueKey("item-$id"),
style: Theme.of(context).textTheme.display1,
),
);
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class _HomePageState extends State<HomePage> {
body: TabBarView(
children: <Widget>[
MyList(
key: ValueKey("list1"),
initialInViewIds: ['0'],
inViewArea: Container(
height: 1.0,
Expand Down
Empty file added example/lib/main_test.dart
Empty file.
3 changes: 2 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ dependencies:
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
flutter_driver:
sdk: flutter
test: any

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
10 changes: 10 additions & 0 deletions example/test_driver/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import 'package:example/main.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_driver/driver_extension.dart';

void main(){
enableFlutterDriverExtension();

runApp(MyApp());
}
45 changes: 45 additions & 0 deletions example/test_driver/app_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

void main() {
group("test scroll fast up and down", () {
FlutterDriver driver;

setUpAll(() async {
driver = await FlutterDriver.connect();
});

tearDownAll(() async {
driver?.close();
});

test("scroll fast", () async {
final listFinder = find.byValueKey("list1");
// scroll to item 1
await driver.scroll(listFinder, 0, -200, Duration(milliseconds: 100));

// hack: force the driver wait 500ms for the notification events be process
await driver.scroll(listFinder, 0, 0, Duration(milliseconds: 500));

var txt1 = await driver.getText(find.byValueKey("item-1"));
var txt2 = await driver.getText(find.byValueKey("item-2"));

// scroll up and down between item 1 & 2.
for (int i = 0; i < 11; ++i) {
await driver.scroll(listFinder, 0, -400, Duration(milliseconds: 100));
await driver.scroll(listFinder, 0, 400, Duration(milliseconds: 100));
}

// hack: force the driver wait 500ms for the notification events be process
await driver.scroll(listFinder, 0, 0, Duration(milliseconds: 500));

// expect item 1 notInView
var txt = await driver.getText(find.byValueKey("item-1"));
expect(txt, txt1);

// expect item 2 notInView
txt = await driver.getText(find.byValueKey("item-2"));
expect(txt, txt2);
});
});
}
10 changes: 9 additions & 1 deletion lib/inview_notifier_list.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart' show describeIdentity;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:stream_transform/stream_transform.dart';
Expand Down Expand Up @@ -111,7 +112,7 @@ class _InViewNotifierListState extends State<InViewNotifierList> {
_streamController = StreamController<ScrollNotification>();

_streamController.stream
.transform(throttle(widget.throttleDuration))
.audit(widget.throttleDuration)

This comment has been minimized.

Copy link
@iptton

iptton Dec 13, 2019

Contributor

using new feature of dart 2.6: extensions.
need to upgrade flutter to flutter 1.12

.listen(_inViewState.onScroll);
}

Expand Down Expand Up @@ -181,6 +182,7 @@ class _InViewNotifierListState extends State<InViewNotifierList> {
if (!_streamController.isClosed && isScrollDirection) {
_streamController.add(notification);
}
return false;
},
),
);
Expand All @@ -204,6 +206,11 @@ class _WidgetData {
final String id;

_WidgetData({@required this.context, @required this.id});

@override
String toString() {
return describeIdentity(this) + " id=$id";
}
}

///Class that stores the context's of the widgets and String id's of the widgets that are
Expand Down Expand Up @@ -231,6 +238,7 @@ class InViewState extends ChangeNotifier {

///Add the widget's context and an unique string id that needs to be notified.
void addContext({@required BuildContext context, @required String id}) {
_contexts.removeWhere((d) => d.id == id);
_contexts.add(_WidgetData(context: context, id: id));
}

Expand Down

0 comments on commit da3a9e4

Please sign in to comment.