【发布时间】:2019-04-01 09:25:41
【问题描述】:
我有一个flutter 应用程序,其中主屏幕是tabBar,如下所示:
class MainRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
body: TabBarView(
physics: NeverScrollableScrollPhysics(),
children: [
Container(
color: Color.fromRGBO(40, 40, 40, 1.0),
child: Tab1(),
),
Container(
color: Color.fromRGBO(40, 40, 40, 1.0),
child: Tab2(),
),
Container(
color: Color.fromRGBO(40, 40, 40, 1.0),
child: Tab3(),
),
],
),
bottomNavigationBar: TabBar(
labelStyle: null,
tabs: [
Tab(
icon: Icon(MdiIcons.home),
),
Tab(
icon: Icon(MdiIcons.settings),
),
Tab(
icon: Icon(MdiIcons.account),
)
],
indicatorColor: Colors.transparent,
labelColor: Color.fromRGBO(255, 255, 255, 1),
unselectedLabelColor: Color.fromRGBO(255, 255, 255, .3),
),
backgroundColor: Colors.black,
),
),
);
例如,我的 Tab3() 看起来像这样:
class Tab3 extends StatefulWidget {
@override
State<StatefulWidget> createState() => Tab3State();
}
class Tab3State extends State<Tab3> {
@override
Widget build(BuildContext context) {
// TODO: Implement build
return Scaffold(
body: Center(
child: Container(
padding: EdgeInsets.only(top: 50),
width: MediaQuery
.of(context)
.size
.width,
height: MediaQuery
.of(context)
.size
.height,
color: Colors.white,
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
child: RaisedButton(
padding: const EdgeInsets.all(20.0),
textColor: Colors.white,
onPressed: () {
print("GAllery tapped");
},
color: Colors.blue,
elevation: 10,
child: Text("Gallery"),
),
),
],
),
),
),
);
}
}
应用程序在模拟器中运行正常,但是当我在真正的 Adnroid 设备上运行时,点击时出现问题。
当显示MainRoute 时,如果我尝试通过点击图标导航到最后一个选项卡,我第一次点击它时无法识别(失焦???),从现在开始按预期工作,仅在第一次点击时与所有选项卡相同。
现在,当 Tab3 加载时,图库按钮无法识别第一次点击(也失焦???),但随后识别第二次点击,并且从现在开始工作。
是不是代码有问题?代码架构有问题?我的真实设备(Samsung Galaxy S7)有问题?
【问题讨论】:
标签: flutter navigationbar