[英]AppBar not showing in scaffold
我已經學習 Flutter 大約 4 天了,它變得乏味,現在我想把一些東西放在一起。 我想在每個屏幕上顯示不同的 AppBar 內容。 但似乎我的 Scaffold 的 AppBar 開始被忽略了。
這是我的代碼:
class Login extends StatelessWidget{
Widget build(BuildContext context){
return Scaffold(appBar: AppBar(title:Text( 'Identification') ), body: Stack( children: [RaisedButton( child: Text("logar"), onPressed: () => {
Navigator.pushNamed(context, '/other-screen')
})]));
}
}
上面的應用欄似乎不可見,不顯示
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'title placedholder',
initialRoute: '/',
routes: {
'/' : (BuildContext context) => Login(),
'/other-screen' : (BuildContext context) => Scaffold(body: Row(children: <Widget>[],))
},
我已將您的代碼復制到DartPad 中,第一個 AppBar 似乎沒問題。 問題出在你的第二頁上。
每次創建新的 Scaffold 時,都需要為其添加一個 AppBar。
嘗試運行flutter clean
然后再次運行它。
我發現當代碼正確但應用程序沒有反映預期的行為時,這可以解決大多數問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.