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

[LinkedScrollController] Added two methods. #398

Open
wants to merge 2 commits 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
7 changes: 7 additions & 0 deletions packages/linked_scroll_controller/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.2.1

* Add `LinkedScrollControllerGroup.applyViewportDimension` method that applies
the viewportDimension of all linked controllers.
* Add `LinkedScrollControllerGroup.notifyListeners` method that notifies
the listener of all linked controllers.

# 0.2.0

* Stable release for null safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ class LinkedScrollControllerGroup {
void resetScroll() {
jumpTo(0.0);
}

/// Applies the viewportDimension of all linked controllers to [value].
void applyViewportDimension(double value) {
for (final controller in _attachedControllers) {
controller.position.applyViewportDimension(value);
}
}

/// Notifies the scroll listener of all linked controllers.
void notifyListeners() {
for (final controller in _attachedControllers) {
controller.position.notifyListeners();
}
}
}

/// This class provides change notification for [LinkedScrollControllerGroup]'s
Expand Down
2 changes: 1 addition & 1 deletion packages/linked_scroll_controller/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: linked_scroll_controller
version: 0.2.0
version: 0.2.1
description: >
A scroll controller that allows two or more scroll views to be in sync.
repository: https://github.com/google/flutter.widgets/tree/master/packages/linked_scroll_controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,52 @@ void main() {
expect(state._controllers.offset, equals(state._letters.offset));
expect(state._controllers.offset, equals(state._numbers.offset));
});

testWidgets('applyViewportDimensions.', (tester) async {
await tester.pumpWidget(Test());
final state = tester.state<TestState>(find.byType(Test));

final viewportDimension = state._letters.position.viewportDimension;

// Change the viewportDimension.
final double changedViewportDimension = viewportDimension - 100;
state._controllers.applyViewportDimension(changedViewportDimension);

await tester.pumpAndSettle();

// The viewportDimension of the connected controllers should change.
expect(
state._letters.position.viewportDimension,
changedViewportDimension,
);
expect(
state._numbers.position.viewportDimension,
changedViewportDimension,
);
});

testWidgets('notifyListeners.', (tester) async {
await tester.pumpWidget(Test());
final state = tester.state<TestState>(find.byType(Test));

int countLettersCalls = 0;
int countNumbersCalls = 0;

// Add listeners.
state._letters.addListener(() {
countLettersCalls += 1;
});
state._letters.addListener(() {
countNumbersCalls += 1;
});

// Notify listeners.
state._controllers.notifyListeners();

// The listener of the registered ScrollController should be called once.
expect(countLettersCalls, 1);
expect(countNumbersCalls, 1);
});
});
}

Expand Down