如何在没有app bar的情况下创建标签栏?

esu*_*esu 8 flutter

我希望在主屏幕上添加标签应用而不是应用栏.如何创建它.目前,我的标签栏添加在应用栏的底部,我已删除标题和标高.同时,我不能说appBar: null因为我需要在标签栏的顶部有一些空间.

Widget HomeTap = new Scaffold(

appBar: new AppBar(
bottom: new TabBar(

    indicatorColor: Colors.pinkAccent[100],
    labelColor: Colors.pinkAccent[100],
    indicatorWeight: 0.5,
    unselectedLabelColor: Colors.grey[400],
    tabs: [
      new Tab(text: 'Album',),
      new Tab(text: 'Artist'),
      new Tab(text: 'Playlist'),
      new Tab(text: 'Songs'),
      new Tab(icon: new Icon(Icons.search))
    ]),
title: null,
elevation: 0.0,
),
body: new TabBarView(
children: [
  new Center(
    child: new AlbumWidget(),
  ),
  new Container(),
  new Container(),
  new Container(),
  new Container(),
],
),
);
Run Code Online (Sandbox Code Playgroud)

Rém*_*let 16

颤动与作曲有关.你可以用其他东西替换任何小部件.他们不仅限于一个特定的孩子.

所以你可以做到

new Scaffold(
   appBar: new TabBar(
      ...
   ),
   ...
)
Run Code Online (Sandbox Code Playgroud)

唯一的要求是您的小部件具有正确的界面.脚手架需要作为appBar一个PreferredSizeWidget.

幸运的是,默认情况下TabBar已经是PreferredSizeWidget.所以不需要改变

  • 当我这样做时,标签栏显示在状态栏下方.即使它是在脚手架. (2认同)

小智 7

 @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(

            title: Text('Tabs Demo'),
          ),
          body:
          Column(
            children: <Widget>[
              TabBar(
                tabs: [
                  Tab(icon: Icon(Icons.directions_car)),
                  Tab(icon: Icon(Icons.directions_transit)),
                  Tab(icon: Icon(Icons.directions_bike)),
                ],
              ),
              Expanded(
                flex: 1,
                child: TabBarView(
                  children: [
                    Icon(Icons.directions_car),
                    Icon(Icons.directions_transit),
                    Icon(Icons.directions_bike),
                  ],
                ),
              )
            ],
          )

        ),
      ),
    );
Run Code Online (Sandbox Code Playgroud)

这对我有用