如何在Flutter应用中隐藏/移除标题栏?

8
如何在Flutter中移除标题栏?
displayMap() {
    mapView.show(new MapOptions(
        mapViewType: MapViewType.normal,
        initialCameraPosition:
        new CameraPosition(new Location(11.052992, 106.681612), 3.0),
        showUserLocation: false,
        title: 'Google Map'));

         .....
  }

我尝试添加Container(height: 0.0)并删除title: 'Google Map',但它只删除了“Google Map”文本。

enter image description here

编辑后:

我的Scaffold

Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Demo App'),
      ),
      body: new Center(
        child: Container(
          child: RaisedButton(
            child: Text('Touch'),
            color: Colors.blue,
            textColor: Colors.white,
            elevation: 7.0,
            onPressed: displayMap,
          ),
        ),
      ),
    );
  }
2个回答

18

在某些情况下,有必要使用AppBar,但不显示标题,其中一种情况是当我们同时具有AppBar和TabBar时。

在这种情况下,您需要删除AppBar标题并包括以下属性:toolbarHeight: 0

DefaultTabController(
  length: 2,
  child: Scaffold(
    backgroundColor: Colors.white,
    appBar: AppBar(
      bottom: TabBar(
        isScrollable: false,
        indicatorColor: Colors.blue,
        onTap: (index) { },
        tabs: [
          Tab(text: "Pending"),
          Tab(text: "Done"),
        ],
      ),
      //this property
      toolbarHeight: 0,
    ), body: TabBarView(...)
  )
)

10

在你的Scaffold中,你需要移除appBar属性:

您的Scaffold中需要删除appBar属性:

    return Scaffold(
        //delete your appBar property in your related Scaffold.
        body: YourBodyWidget(),
    );

编辑:这与map_view插件相关。

  MapOptions(
      {this.showUserLocation: false,
      this.showMyLocationButton: false,
      this.showCompassButton: false,
      this.hideToolbar = false,
      this.initialCameraPosition: _defaultCamera,
      this.title: "",
      this.mapViewType: MapViewType.normal});

这些是默认的MapOptions,也许你可以尝试设置hideToolbar:true,但我认为这不是你想要的。

我认为他们没有提供关闭appBar的参数。

最后,我建议使用google_maps_flutter插件,该插件仅呈现地图,并由Flutter团队开发,因此您可以轻松配置页面/脚手架中的其他项目。


在我的 Scaffold 中,我已经删除了 AppBar: new AppBar( title: new Text('Demo App'), ), 并且在 displayMap() 中删除了 title,但这并不可行。 - Alex

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接