【问题标题】:Flutter Scaffold Appbar not showing the back buttonFlutter Scaffold Appbar 不显示后退按钮
【发布时间】:2020-05-22 15:39:19
【问题描述】:

我的班级没有在 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);
  }
}

【问题讨论】:

  • 您是如何导航到此小部件的?要让应用栏显示后退按钮,必须有某个地方可以返回到 ie。堆栈上必须有另一个(以前的)路由。

标签: flutter dart


【解决方案1】:

根据文档,如果你使用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,
), 

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      还有 _goBack 方法:

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

      }

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:
          1. 您应该确保创建应用栏:AppBar()
          2. 并且应该在主题中设置颜色,直到图标可能为白色

          【讨论】:

            猜你喜欢
            • 2018-02-08
            • 1970-01-01
            • 1970-01-01
            • 2023-02-05
            • 1970-01-01
            • 2020-09-28
            • 1970-01-01
            • 1970-01-01
            • 2021-06-03
            相关资源
            最近更新 更多