@@ -519,26 +519,35 @@ class _TabBarScrollPosition extends ScrollPositionWithSingleContext {
519
519
520
520
final _TabBarState tabBar;
521
521
522
- bool ? _initialViewportDimensionWasZero;
522
+ bool _viewportDimensionWasNonZero = false ;
523
+
524
+ // Position should be adjusted at least once.
525
+ bool _needsPixelsCorrection = true ;
523
526
524
527
@override
525
528
bool applyContentDimensions (double minScrollExtent, double maxScrollExtent) {
526
529
bool result = true ;
527
- if (_initialViewportDimensionWasZero != true ) {
528
- // If the viewport never had a non-zero dimension, we just want to jump
529
- // to the initial scroll position to avoid strange scrolling effects in
530
- // release mode: In release mode, the viewport temporarily may have a
531
- // dimension of zero before the actual dimension is calculated. In that
532
- // scenario, setting the actual dimension would cause a strange scroll
533
- // effect without this guard because the super call below would starts a
534
- // ballistic scroll activity.
535
- assert (viewportDimension != null );
536
- _initialViewportDimensionWasZero = viewportDimension != 0.0 ;
530
+ if (! _viewportDimensionWasNonZero) {
531
+ _viewportDimensionWasNonZero = viewportDimension != 0.0 ;
532
+ }
533
+ // If the viewport never had a non-zero dimension, we just want to jump
534
+ // to the initial scroll position to avoid strange scrolling effects in
535
+ // release mode: In release mode, the viewport temporarily may have a
536
+ // dimension of zero before the actual dimension is calculated. In that
537
+ // scenario, setting the actual dimension would cause a strange scroll
538
+ // effect without this guard because the super call below would starts a
539
+ // ballistic scroll activity.
540
+ if (! _viewportDimensionWasNonZero || _needsPixelsCorrection) {
541
+ _needsPixelsCorrection = false ;
537
542
correctPixels (tabBar._initialScrollOffset (viewportDimension, minScrollExtent, maxScrollExtent));
538
543
result = false ;
539
544
}
540
545
return super .applyContentDimensions (minScrollExtent, maxScrollExtent) && result;
541
546
}
547
+
548
+ void markNeedsPixelsCorrection () {
549
+ _needsPixelsCorrection = true ;
550
+ }
542
551
}
543
552
544
553
// This class, and TabBarScrollPosition, only exist to handle the case
@@ -1027,6 +1036,13 @@ class _TabBarState extends State<TabBar> {
1027
1036
if (widget.controller != oldWidget.controller) {
1028
1037
_updateTabController ();
1029
1038
_initIndicatorPainter ();
1039
+ // Adjust scroll position.
1040
+ if (_scrollController != null ) {
1041
+ final ScrollPosition position = _scrollController! .position;
1042
+ if (position is _TabBarScrollPosition ) {
1043
+ position.markNeedsPixelsCorrection ();
1044
+ }
1045
+ }
1030
1046
} else if (widget.indicatorColor != oldWidget.indicatorColor ||
1031
1047
widget.indicatorWeight != oldWidget.indicatorWeight ||
1032
1048
widget.indicatorSize != oldWidget.indicatorSize ||
0 commit comments