简体   繁体   English

为什么在 flutter App 中添加“Sliver AppBar”后显示两个 AppBar

[英]Why it shows two AppBars after adding 'Sliver AppBar' in flutter App

I have added 'Sliver AppBar' into Scaffold of my app and I am wondering why it shows two app bars now.我在我的应用程序的脚手架中添加了“Sliver AppBar”,我想知道为什么它现在显示两个应用程序栏。 The Scaffold contains only one drawer but in UI, it shows two drawers. Scaffold 仅包含一个抽屉,但在 UI 中,它显示了两个抽屉。 Anybody know what is going wrong.任何人都知道出了什么问题。

return Scaffold(
  body: CustomScrollView(
    slivers: <Widget>[
      SliverAppBar(
        bottom: AppBar(
          title: SizedBox(
            height: 45,
            child: TextField(
              decoration: InputDecoration(
                contentPadding: EdgeInsets.only(top: 5, left: 15),
                suffixIcon: IconButton(
                  icon: Icon(Icons.search),
                  onPressed: () {
                  },
                ),
                filled: true,
                fillColor: Colors.white,
                hintText: "What are you looking for ?",
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(5),
                ),
              ),
            ),
          ),
          
        ),
      ),
      
  drawer: Drawer(),
  
);

在此处输入图像描述

After removing SliverAppBar from the code, it shows blank screen.从代码中删除 SliverAppBar 后,它显示空白屏幕。 So, it is confirmed that the two AppBars are coming from above code only.因此,可以确认这两个 AppBar 仅来自上述代码。

在此处输入图像描述

SliverAppBar itself a appBar and bottom: AppBar is another one, you can use PreferredSize on bottom . SliverAppBar本身是一个appBarbottom: AppBar是另一个,您可以在bottom使用PreferredSize

SliverAppBar(
  bottom: PreferredSize(
    preferredSize: Size.fromHeight(45),
    child: TextField(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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