Repository navigation
Tabbar.image does not render at initialIndex for the first time #59143
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: assetsPackaging, accessing, or using assetsPackaging, accessing, or using assetsa: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagesfound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Description
✓] Flutter (Channel stable, v1.17.3, on Mac OS X 10.15.5 19F101, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.45.1)
[✓] Connected device (1 available)

TabBar(
labelColor: Theme.of(context).accentColor,
unselectedLabelColor: Theme.of(context).hintColor,
indicatorSize: TabBarIndicatorSize.label,
indicator: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/618.png'),
fit: BoxFit.cover,
),
),
isScrollable: true,
tabs: _tabs.map((String name) => Tab(text: name)).toList(),
),
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: assetsPackaging, accessing, or using assetsPackaging, accessing, or using assetsa: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagesfound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Activity
iapicca commentedon Jun 10, 2020
Hi @mzl1988
it is possible the the widget containing the TabBar is build
before the image is loaded
could you please provide a minimal complete reproducible code sample.
Thank you
mzl1988 commentedon Jun 12, 2020
Hi, This is my code, thanks! https://github.com/mzl1988/tabbar_indicator_test

iapicca commentedon Jun 12, 2020
Hi @mzl1988
I've tested this modified version of your code sample with the latest master
code
doctor
I can reproduce the issue
Thank you
OctMon commentedon Aug 6, 2020
Try this.
Nomeleel commentedon Nov 14, 2020
30 remaining items
Mahm0ud-Ahmed commentedon Aug 2, 2024
Cedar-byte commentedon Nov 4, 2024
Works for me. Thanks.
jingkeling commentedon Dec 2, 2025
huycozy commentedon Dec 8, 2025
I'm looking at this issue and found why this happens:
TabBar is using _indicatorPainter, which is a CustomPainter to manage painting things in the whole bar, and each image on tabs is painted by a BoxPainter named
_painter, which also takes image configuration:flutter/packages/flutter/lib/src/material/tabs.dart
Line 571 in 6ff4a4a
flutter/packages/flutter/lib/src/material/tabs.dart
Lines 582 to 595 in 6ff4a4a
In this scenario, image is loaded asynchronously, so tracing the flow, we will see what happened inside as below:
1 . In _indicatorPainter, it requests to create a boxpainter:
flutter/packages/flutter/lib/src/material/tabs.dart
Line 571 in 6ff4a4a
flutter/packages/flutter/lib/src/painting/box_decoration.dart
Lines 536 to 540 in 2343d68
flutter/packages/flutter/lib/src/painting/decoration_image.dart
Line 375 in 2343d68
Inside _handleImage, if it's a non-synchronousCall,
_onChangedcallback is called:flutter/packages/flutter/lib/src/painting/decoration_image.dart
Lines 423 to 425 in 2343d68
_onChangedtriggersmarkNeedsPaintcallback, but inmarkNeedsPaint, it only sets_needsPaintflag to true but doesn't actually trigger a repaint. I did debugging and saw that shouldRepaint is not invoked, even though_needsPaintis true already.I have an idea to fix this, it's on the way.
Fix TabBar.image does not render at initialIndex for the first time (#…
github-actions commentedon Jan 21, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Fix TabBar.image does not render at initialIndex for the first time (…
Fix TabBar.image does not render at initialIndex for the first time (…