-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Nested TabBar&TabBarView - first tab scroll out when open app #28007
Comments
Please add the output of To investigate we would need a minimal runnable reproduction Please consider asking on StackOverflow before creating an issue and only create an issue if it turns out to be a Flutter bug or missing feature. |
only show in profile or release modeoutput
codeimport 'package:flutter/material.dart';
const ProjectTitle = 'RX-0';
const EnableBroadcast = true;
enum BLTabItem { home, feed, favorite, discovery, mine }
String titleForTabItem(BLTabItem item) {
switch (item) {
case BLTabItem.home:
return '首页';
case BLTabItem.feed:
return '推荐';
case BLTabItem.favorite:
return '关注';
case BLTabItem.discovery:
return '发现';
case BLTabItem.mine:
return '我的';
}
return null;
}
Icon iconForTabItem(BLTabItem item) {
switch (item) {
case BLTabItem.home:
return Icon(Icons.home);
case BLTabItem.feed:
return Icon(Icons.list);
case BLTabItem.favorite:
return Icon(Icons.favorite);
case BLTabItem.discovery:
return Icon(Icons.info);
case BLTabItem.mine:
return Icon(Icons.account_circle);
}
return null;
}
void main() => runApp(BLApp());
class BLApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(title: ProjectTitle, home: EntranceScaffold());
}
}
class EntranceScaffold extends StatefulWidget {
@override
_EntranceScaffoldState createState() => _EntranceScaffoldState();
}
class _EntranceScaffoldState extends State<EntranceScaffold> {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: BLTabItem.values.length,
child: Scaffold(
body: TabBarView(
children:
BLTabItem.values.map((BLTabItem item) => HomeTab()).toList(),
),
bottomNavigationBar: Material(
color: Colors.white,
child: SafeArea(
child: Container(
height: 65,
decoration: BoxDecoration(
color: const Color(0xFFF0F0F0),
boxShadow: <BoxShadow>[
BoxShadow(
color: const Color(0xFFd0d0d0),
blurRadius: 4.0,
spreadRadius: 2.0,
offset: Offset(-1.0, -1.0),
),
],
),
child: TabBar(
indicatorColor: Colors.transparent,
labelColor: Theme.of(context).primaryColor,
unselectedLabelColor: const Color(0xFF8E8E8E),
tabs: BLTabItem.values
.map((item) => Tab(
text: titleForTabItem(item),
icon: iconForTabItem(item)))
.toList()),
))),
floatingActionButton: EnableBroadcast
? Builder(builder: (BuildContext context) {
return FloatingActionButton(
child: Text('开播'),
onPressed: () {
final snackBar = SnackBar(
content: Text('主播开播', textAlign: TextAlign.center),
duration: Duration(milliseconds: 1500));
Scaffold.of(context).showSnackBar(snackBar);
});
})
: null),
);
}
}
class HomeTab extends StatefulWidget {
@override
_HomeTabState createState() => _HomeTabState();
}
class _HomeTabState extends State<HomeTab> with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 6,
child: Scaffold(
appBar: AppBar(
// 大量配置属性参考 SliverAppBar 示例
title: Text('TabBar'),
leading: Icon(Icons.home),
backgroundColor: Colors.amber[1000],
bottom: TabBar(
isScrollable: true,
tabs: <Widget>[
Tab(text: "Tabs 1"),
Tab(text: "Tabs 2"),
Tab(text: "Tabs 3"),
Tab(text: "Tabs 4"),
Tab(text: "Tabs 5"),
Tab(text: "Tabs 6"),
],
),
),
body: TabBarView(children: <Widget>[
Text('TabsView 1'),
Text('TabsView 2'),
Text('TabsView 3'),
Text('TabsView 4'),
Text('TabsView 5'),
Text('TabsView 6'),
]),
));
}
} |
I can't reproduce it with |
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 |
looks like
should be
The text was updated successfully, but these errors were encountered: