简体   繁体   English

如何在 flutter 中创建可滚动标签

[英]How to create scrollable tabs in flutter

In the web world I have scrollable tabs offered by material-ui that looks like that.在 web 世界中,我有 material-ui 提供的可滚动标签,看起来像这样。 在此处输入图像描述

I am trying create the same thing using flutter, I did a listview in a row however I am unable to create the next and previous buttons.我正在尝试使用 flutter 创建相同的东西,我连续做了一个列表视图,但是我无法创建nextprevious按钮。

Help or a reference of the widget if it is already made is highly appreciated.如果已经制作了小部件的帮助或参考,我们将不胜感激。 Thank you谢谢

Check this out看一下这个

Builder(
          builder: (context) {
            return Row(
              children: [
                IconButton(
                  icon: Icon(Icons.arrow_back_ios),
                  onPressed: (){
                    if(_tabController.index > 0){
                      _tabController.animateTo(_tabController.index - 1);
                    }else{
                      Scaffold.of(context).showSnackBar(SnackBar(content: Text("Can't go back"),));
                    }
                  },
                ),
                Expanded(
                  child: TabBar(
                    isScrollable: true,
                    controller: _tabController,
                    labelStyle: TextStyle(
                      color: Colors.black
                    ),
                    unselectedLabelColor: Colors.black,
                    labelColor: Colors.blue,
                    tabs: List.generate(
                      20,
                      (index) {
                        return Tab(
                          text: "Tab $index",
                        );
                      },
                    ),
                  ),
                ),
                IconButton(
                  icon: Icon(Icons.arrow_forward_ios),
                  onPressed: (){
                    if(_tabController.index+1 < 20){
                      _tabController.animateTo(_tabController.index + 1);
                    }else{
                      Scaffold.of(context).showSnackBar(SnackBar(content: Text("Can't move forward"),));
                    }
                  },
                ),
              ],
            );
          }
        )

在此处输入图像描述

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

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