Flutter 如何制作无限圆形制表符?

Flutter 如何制作无限圆形制表符?,flutter,Flutter,我使用的是典型的tabs解决方案(),我必须使滑动无限大并循环 示例(3个选项卡):Tab1->Tab2->Tab3->Tab1->Tab2。。。等 可能吗 谢谢 我认为不能直接使用TabBar,但您可以使用ListView.builder在水平方向上进行自定义TabBar:),而不使用itemCount。。。(显然,您必须使用onTap或GestureDetector等添加自己的项目小部件) class SampleInfiniteTab扩展StatefulWidget{ @凌驾 _Sampl

我使用的是典型的tabs解决方案(),我必须使滑动无限大并循环

示例(3个选项卡):Tab1->Tab2->Tab3->Tab1->Tab2。。。等

可能吗


谢谢

我认为不能直接使用TabBar,但您可以使用ListView.builder在水平方向上进行自定义TabBar:),而不使用itemCount。。。(显然,您必须使用onTap或GestureDetector等添加自己的项目小部件)

class SampleInfiniteTab扩展StatefulWidget{
@凌驾
_SampleInfiniteTabState createState()=>_SampleInfiniteTabState();
}
类_SampleInfiniteTabsState扩展状态{
列表选项卡;
@凌驾
void initState(){
tabs=List.generate(
10,
(idx)=>选项卡(
子项:文本(“我的选项卡$idx”),
));
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
底部:MyCustomTabBar(
标签:标签,
),
),
);
}
}
类MyCustomTabBar扩展无状态小部件实现PreferredSizeWidget{
最终列表选项卡;
静态常数双kTabBarHeight=80;
constMyCustomTabbar({Key-Key,this.tabs}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
返回容器(
颜色:颜色,白色,
子项:buildTabs(),
高度:kTabBarHeight,
);
}
buildTabs(){
返回ListView.builder(
项目生成器:(ctx、idx){
var tab=tabs[idx%tabs.length];
返回容器(
宽度:200,
颜色:颜色,红色,
子:选项卡,
);
},
滚动方向:轴水平,
);
}
@凌驾
大小获取首选大小{
返回大小.fromHeight(kTabBarHeight);
}
}

欢迎来到堆栈溢出。请向我们展示您迄今为止所做的尝试。
class SampleInfiniteTabs extends StatefulWidget {
  @override
  _SampleInfiniteTabsState createState() => _SampleInfiniteTabsState();
}

class _SampleInfiniteTabsState extends State<SampleInfiniteTabs> {
  List<Tab> tabs;

  @override
  void initState() {
    tabs = List.generate(
        10,
        (idx) => Tab(
              child: Text("My Tab $idx"),
            ));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        bottom: MyCustomTabBar(
          tabs: tabs,
        ),
      ),
    );
  }
}

class MyCustomTabBar extends StatelessWidget implements PreferredSizeWidget {
  final List<Widget> tabs;

  static const double kTabBarHeight = 80;

  const MyCustomTabBar({Key key, this.tabs}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: buildTabs(),
      height: kTabBarHeight,
    );
  }

  buildTabs() {
    return ListView.builder(
      itemBuilder: (ctx, idx) {
        var tab = tabs[idx % tabs.length];
        return Container(
          width: 200,
          color: Colors.red,
          child: tab,
        );
      },
      scrollDirection: Axis.horizontal,
    );
  }

  @override
  Size get preferredSize {
    return Size.fromHeight(kTabBarHeight);
  }
}