【问题标题】:Back Button displaced title of AppBar后退按钮取代了 AppBar 的标题
【发布时间】:2020-09-09 03:33:01
【问题描述】:

就像标题一样,我用 Navigator.push() 在新页面中创建了一个按钮,页面自动在 appBar 上生成一个后退按钮,我很欣赏自动生成的后退按钮,但我希​​望后退按钮不会取代我的标题的定位,可以吗?

下面是我进入这个页面的按钮代码:

Navigator.of(context).push(
                          MaterialPageRoute(
                            builder: (context) {
                              return FeedTest();
                            },
                          ),
                        );

这是我新页面的完整代码:

Widget build(BuildContext context) {
return ScrollConfiguration(
  behavior: MyBehavior(),
  child: SafeArea(
    child: DefaultTabController(
      length: 2,
      child: Scaffold(
        backgroundColor: Colors.black,
        appBar: AppBar(
          elevation: 0,
          backgroundColor: Colors.grey[850],
          title: Flex(
              direction: Axis.horizontal,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Image.asset(
                  'images/logo2.png',
                  isAntiAlias: true,
                  scale: 1.8,
                  fit: BoxFit.fitHeight,
                  alignment: Alignment.center,
                )
              ]),
          bottom: TabBar(
            indicatorColor: Colors.white,
            tabs: [
              Tab(
                text: 'Submit Feedback',
              ),
              Tab(
                text: 'Submit Testimony',
              )
            ],
          ),
        ),
        body: TabBarView(
          children: [SubmitFeedback(), SubmitTestimony()],
        ),
      ),
    ),
  ),
);

}

附:出于隐私目的,标题图片已被模糊处理

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    centerTitle: true用于使AppBar中的标题居中

    AppBar(
      centerTitle: true, 
      ...
    )
    

    输出:

    【讨论】:

      【解决方案2】:

      使用centerTitle: true,如下所示。

      AppBar(
        centerTitle: true, // this is all you need
        //Rest Code here
      )
      

      我上传完整的代码如下。

      Widget build(BuildContext context) {
      return ScrollConfiguration(
        behavior: MyBehavior(),
        child: SafeArea(
          child: DefaultTabController(
            length: 2,
            child: Scaffold(
              backgroundColor: Colors.black,
              appBar: AppBar(
                centerTitle: true,
                elevation: 0,
                backgroundColor: Colors.grey[850],
                title: Flex(
                    direction: Axis.horizontal,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Image.asset(
                        'images/logo2.png',
                        isAntiAlias: true,
                        scale: 1.8,
                        fit: BoxFit.fitHeight,
                        alignment: Alignment.center,
                      )
                    ]),
                bottom: TabBar(
                  indicatorColor: Colors.white,
                  tabs: [
                    Tab(
                      text: 'Submit Feedback',
                    ),
                    Tab(
                      text: 'Submit Testimony',
                    )
                  ],
                ),
              ),
              body: TabBarView(
                children: [SubmitFeedback(), SubmitTestimony()],
              ),
            ),
          ),
        ),
      );
      }
      

      【讨论】:

        猜你喜欢
        • 2018-02-08
        • 2020-05-22
        • 1970-01-01
        • 2021-11-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-16
        • 1970-01-01
        相关资源
        最近更新 更多