颤动选项卡失去焦点或没有响应点击

问题描述 投票:0回答:1

我有一个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"),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

该应用程序在模拟器中运行正常,但是当我在真正的Android设备上运行时,它有一个问题。

当显示MainRoute时,如果我尝试通过点击图标导航到最后一个标签,第一次点击它时无法识别(失焦)???第二次从现在起它按预期工作,同样仅在第一次点按时显示所有标签。

现在,当加载Tab3时,Gallery按钮不能识别第一次点击(也没有焦点???),但是第二次点击被识别并且从现在开始工作。

这是代码的问题吗?代码体系结构的问题?我的真实设备(三星Galaxy S7)有问题吗?

flutter navigationbar
1个回答
0
投票

我不知道它是否相关,但你不应该有2个Scaffold小部件。尝试删除Tab3State类中的那个,无论如何你都不需要它。

© www.soinside.com 2019 - 2024. All rights reserved.