[英]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,
),
默認情況下,后退按鈕都在那里。 我構建並部署了一些用戶的后退按鈕,而不是其他用戶。 我的天哪,這個平台一天比一天壞。 我不應該在手動彈出 function 中明確創建后退按鈕和接線,當文檔明確指出它是演出的一部分時,它在某些情況下可以在某些設備上工作,但絕對不一致。 (嘆)
嘗試制作自己的后退按鈕:
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.