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

Preventing scrolling to last visible child when expansion behaviour is none #28

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 18 additions & 5 deletions lib/tree_view/tree_view_state_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class TreeViewStateHelper<Data> {
animatedListStateController.insertAll(
animatedListStateController.list.length, List.from(event.items));
}
expansionBehaviourController.scrollToLastVisibleChild(root);
expansionBehaviourController.scrollToLastVisibleChild(root,
bypass: expansionBehaviourController.expansionBehavior ==
ExpansionBehavior.none);
} else {
final parentIndex = animatedListStateController.list
.indexWhere((element) => element.key == node.parent?.key);
Expand All @@ -72,7 +74,9 @@ class TreeViewStateHelper<Data> {
parentIndex + parentNode.childrenAsList.length,
List.from(event.items));
}
expansionBehaviourController.scrollToLastVisibleChild(parentNode);
expansionBehaviourController.scrollToLastVisibleChild(parentNode,
bypass: expansionBehaviourController.expansionBehavior ==
ExpansionBehavior.none);
}
}
}
Expand All @@ -92,7 +96,9 @@ class TreeViewStateHelper<Data> {
: event.index,
List.from(event.items));
}
expansionBehaviourController.scrollToLastVisibleChild(node.root);
expansionBehaviourController.scrollToLastVisibleChild(node.root,
bypass: expansionBehaviourController.expansionBehavior ==
ExpansionBehavior.none);
} else {
final parentIndex = animatedListStateController.list
.indexWhere((element) => element.key == node.parent?.key);
Expand All @@ -106,7 +112,9 @@ class TreeViewStateHelper<Data> {
animatedListStateController.insertAll(
parentIndex + 1 + event.index, List.from(event.items));
}
expansionBehaviourController.scrollToLastVisibleChild(parentNode);
expansionBehaviourController.scrollToLastVisibleChild(parentNode,
bypass: expansionBehaviourController.expansionBehavior ==
ExpansionBehavior.none);
}
}
}
Expand Down Expand Up @@ -278,7 +286,12 @@ class TreeViewExpansionBehaviourController<Data> {
}
}

Future<void> scrollToLastVisibleChild(INode parent) async {
Future<void> scrollToLastVisibleChild(INode parent,
{bool bypass = false}) async {
if (bypass) {
return;
}

final lastChild = parent.childrenAsList.lastOrNull;
if (lastChild == null) return;

Expand Down