Flutter Scaffold Appbar 不显示后退按钮

Vin*_*del 18 dart flutter

我的课程没有在 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);
  }
}
Run Code Online (Sandbox Code Playgroud)

ayo*_*bra 17

我使用了这个解决方案,它对我有用,在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,
          ),
        ),
      )
Run Code Online (Sandbox Code Playgroud)


tha*_*h84 9

根据该文档,如果您使用 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,
), 
Run Code Online (Sandbox Code Playgroud)


Sam*_*h.K 1

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

     appBar: AppBar(
                    leading: IconButton(
                    icon: Icon(Icons.arrow_back_ios),
                    iconSize: 20.0,
                    onPressed: () {
                      _goBack(context);
                    },
                  ),
                  centerTitle: true,
                  title: Text('back')),
Run Code Online (Sandbox Code Playgroud)

和 _goBack 方法:

 _goBack(BuildContext context) {
Navigator.pop(context);
Run Code Online (Sandbox Code Playgroud)

}