简体   繁体   中英

Flutter Scaffold Appbar not showing the back button

My class is not showing the back button in the AppBar,

Already try put 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);
  }
}

I used this solution, it works for me, add leading inside 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,
          ),
        ),
      )

In order for the back key to come, the part that goes to that page is "Navigator.pushNamed (context, '/ brand new');" For example, it should be in the form of.

According to the document, if you use Material design and push a screen, the back button should be there.

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

But sometimes the back button and app bar background color are the same, so it is invisible. Let try to click on the leading button zone or set to a contrary color

appBar: AppBar(
  iconTheme: IconThemeData(
    color: Colors.black, //change your color here
  ),
  title: Text("Sample"),
  centerTitle: true,
), 
  1. you should to be sure a create appbar : AppBar()
  2. and should to set a color in the theme until maybe icon is white

The back buttons were all there by default. I built and deployed, the back buttons are there for some users, not for others. My goodness, this platform is getting buggier and buggier by the day. I shouldn't have to explicitly create a back button and wire in a manual pop function when the documentation clearly states it's part of the gig, and it works on some devices under some circumstances, with absolutely no consistency. (sigh)

To show back button only with custom color, and appbar background white or any color

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,
          ),

Result在此处输入图像描述

Try to make your own back button :

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

And the _goBack method :

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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