如何删除 Flutter 中的第二个 appbar

Kam*_*san 5 appbar flutter

我正在尝试使用 构建一个演示聊天应用程序Flutter。在主屏幕之后,我通常Navigator.push会转到详细信息屏幕。问题截图:

问题截图

第一个屏幕的构建方法:

@override
 Widget build(BuildContext context) {
return Scaffold(
    appBar: AppBar(
      title: const Text("Chat Thread App"),
      actions: <Widget>[
        IconButton(
          icon: Icon(Icons.settings),
          onPressed: () {
            Navigator.pushNamed(context, '/settings');
          },
        )
      ],
    ),
    body: isLoading
        ? Center(
            child: CircularProgressIndicator(),
          )
        : new ChatThreadListCard(messageThreads: _messageThreadLists, user: _user,),
);
}
Run Code Online (Sandbox Code Playgroud)

方法代码Navigator.push

Navigator.push(context, MaterialPageRoute(
        builder: (context) => ChatDetailsScreen(threadModel: new ThreadModel(
              user.id, 
              user.fullName, 
              user.pic, 
              "otherId", 
              "otherName", 
              "otherPic", 
              post.threadId
            )
          ),
      ),);
Run Code Online (Sandbox Code Playgroud)

第二个屏幕的构建方法,其中产生了问题:

return Scaffold(
  appBar: AppBar(
    title: Text("Chat demo"),
  ),
  body: WillPopScope(
    child: isLoading
        ? Center(
            child: CircularProgressIndicator(),
          )
        : Stack(
            alignment: AlignmentDirectional.bottomCenter,
            children: <Widget>[
              SizedBox(
                width: 300,
                height: 300,
              ),
              Column(
                children: <Widget>[
                  buildChat(),
                  buildInput(),
                ],
              )
            ],
          ),
    onWillPop: onBackPress,
  ),
);
Run Code Online (Sandbox Code Playgroud)

Sna*_*ips 1

我猜你设置的地方有些东西不正常Material App

应用程序.dart:

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: HomePage());
  }
}
Run Code Online (Sandbox Code Playgroud)

首页和第二页

import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  @override
  State createState() => HomePageState();
}

class HomePageState extends State<HomePage> with TickerProviderStateMixin {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('First Page'),
        ),
        body: Container(
          child: Center(child: RaisedButton(child: Text('Forward'), onPressed: () async {
            await Navigator.push(context, MaterialPageRoute(builder: (context) => SecondPage()));
          },)),
        ));
  }
}

class SecondPage extends StatefulWidget {
  @override
  State createState() => SecondPageState();
}

class SecondPageState extends State<SecondPage> with TickerProviderStateMixin {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Second Page'),
        ),
        body: Container(
          child: Center(child: RaisedButton(child: Text('Backward'), onPressed: () {
            Navigator.of(context).pop();
          },)),
        ));
  }
}
Run Code Online (Sandbox Code Playgroud)

其产生:

导航演示