简体   繁体   English

如何在颤振中嵌套标签?

[英]How to nest tab in flutter?

How to nest tab view as a child of column in flutter?如何在flutter中将选项卡视图嵌套为列的子项?

I don't want to add tabs as a child of app bar bottom cause my tabs are not on top.我不想将标签添加为应用栏bottom的子项,因为我的标签不在顶部。 It is somewhere in the body.它在身体的某个地方。

So I tried the above method & also I tried wrapping it inside a nested scaffold.所以我尝试了上面的方法,我也尝试将它包裹在一个嵌套的脚手架中。 Both of them seems not working.他们两个似乎都不起作用。

Following is what I've tried.以下是我尝试过的。

      body: SingleChildScrollView(
        physics: BouncingScrollPhysics(),
        child: Container(
          child: Column(children: [
            Container(
              padding: EdgeInsets.all(10),
              child: TextInput(
                placeholder: 'Search',
                leadingIcon: searchIcon,
              ),
            ),
            DefaultTabController(
              length: 3,
              child: Column(
                children: [
                  TabBar(
                    tabs: [
                      Tab(icon: Icon(Icons.directions_car)),
                      Tab(icon: Icon(Icons.directions_transit)),
                      Tab(icon: Icon(Icons.directions_bike)),
                    ],
                  ),
                  TabBarView(
                    children: [
                      Icon(Icons.directions_car),
                      Icon(Icons.directions_transit),
                      Icon(Icons.directions_bike),
                    ],
                  ),
                ],
              ),
            ),

give a height to tabcontroller and then wrap tabbarview with expanded.给 tabcontroller 一个高度,然后用扩展包装 tabbarview。

body: SingleChildScrollView(
        physics: BouncingScrollPhysics(),
        child: Container(
          child: Column(children: [
            Container(
              height:10,
              padding: EdgeInsets.all(10),
            ),
            Container(
              height:100,//add height as per your need
              child:DefaultTabController(
              length: 3,
              child: Column(
                children: [
                  TabBar(
                    tabs: [
                      Tab(icon: Icon(Icons.directions_car)),
                      Tab(icon: Icon(Icons.directions_transit)),
                      Tab(icon: Icon(Icons.directions_bike)),
                    ],
                  ),
                  Expanded(
                    child:TabBarView(
                    children: [
                      Icon(Icons.directions_car),
                      Icon(Icons.directions_transit),
                      Icon(Icons.directions_bike),
                    ],
                  ),
                  ),
                ],
              ),
            ),
            ),
            ])))

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

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