繁体   English   中英

Flutter 脚手架 Appbar 不显示后退按钮

[英]Flutter Scaffold Appbar not showing the back button

我的 class 没有在 AppBar 中显示后退按钮,

已经尝试把 this.automaticallyImplyLeading = true,

import 'package:carros/pages/carro/carro.dart';
import 'package:flutter/material.dart';

class CarroPage extends StatelessWidget {
  Carro carro;
  CarroPage(this.carro);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(carro.nome),
      ),
      body: _body(),
    );
  }

  _body() {
    return Image.network(carro.urlFoto);
  }
}

我使用了这个解决方案,它对我有用,在 AppBar 中添加前导:

appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0.0,
        titleSpacing: 10.0,
        centerTitle: true,
        leading: InkWell(
          onTap: () {
            Navigator.pop(context);
          },
          child: Icon(
            Icons.arrow_back_ios,
            color: Colors.black54,
          ),
        ),
      )

为了得到后退键,进入该页面的部分是“Navigator.pushNamed (context, '/brand new');” 例如,它应该是 的形式。

根据文档,如果您使用 Material design 并按下屏幕,则后退按钮应该在那里。

https://api.flutter.dev/flutter/material/AppBar-class.html

但是有时候返回按钮和应用栏背景颜色是一样的,所以是不可见的。 让我们尝试单击前导按钮区域或设置为相反的颜色

appBar: AppBar(
  iconTheme: IconThemeData(
    color: Colors.black, //change your color here
  ),
  title: Text("Sample"),
  centerTitle: true,
), 
  1. 您应该确保创建 appbar : AppBar()
  2. 并且应该在主题中设置颜色,直到图标变为白色

默认情况下,后退按钮都在那里。 我构建并部署了一些用户的后退按钮,而不是其他用户。 我的天哪,这个平台一天比一天坏。 我不应该在手动弹出 function 中明确创建后退按钮和接线,当文档明确指出它是演出的一部分时,它在某些情况下可以在某些设备上工作,但绝对不一致。 (叹)

仅显示自定义颜色的后退按钮,以及白色或任何颜色的应用栏背景

appBar: AppBar(
            elevation: 0,
            backgroundColor: Colors.white,
            leading: IconButton(
              color: Colors.black,
              icon: Icon(Icons.arrow_back_ios),
              iconSize: 20.0,
              onPressed: () {
                Navigator.pop(context);
              },
            ),
            centerTitle: true,
          ),

结果在此处输入图像描述

尝试制作自己的后退按钮:

     appBar: AppBar(
                    leading: IconButton(
                    icon: Icon(Icons.arrow_back_ios),
                    iconSize: 20.0,
                    onPressed: () {
                      _goBack(context);
                    },
                  ),
                  centerTitle: true,
                  title: Text('carro.nome')),

和 _goBack 方法:

 _goBack(BuildContext context) {
Navigator.pop(context);

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM