Skip to content

Commit

Permalink
[Tabs] Fix tab indicator flies off issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nero-angela committed Nov 13, 2020
1 parent 7cda686 commit 38f2bc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/flutter/lib/src/material/tab_controller.dart
Expand Up @@ -224,6 +224,7 @@ class TabController extends ChangeNotifier {
.whenCompleteOrCancel(() {
if (_animationController != null) { // don't notify if we've been disposed
_indexIsChangingCount -= 1;
_indexPositionWhenTapping = _animationController!.value;
notifyListeners();
}
});
Expand All @@ -235,6 +236,13 @@ class TabController extends ChangeNotifier {
}
}

/// the value of animation controller at the moment of tapping a tab
///
/// This value is needed to calculate the position of the indicator
/// when selecting a tab during animation.
double get indexPositionWhenTapping => _indexPositionWhenTapping ?? _previousIndex.toDouble();
double? _indexPositionWhenTapping;

/// The index of the currently selected tab.
///
/// Changing the index also updates [previousIndex], sets the [animation]'s
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/tabs.dart
Expand Up @@ -302,7 +302,7 @@ class _TabLabelBar extends Flex {

double _indexChangeProgress(TabController controller) {
final double controllerValue = controller.animation!.value;
final double previousIndex = controller.previousIndex.toDouble();
final double previousIndex = controller.indexPositionWhenTapping;
final double currentIndex = controller.index.toDouble();

// The controller's offset is changing because the user is dragging the
Expand Down

0 comments on commit 38f2bc0

Please sign in to comment.