简体   繁体   English

如何在 flutter 中管理“TabBarView”?

[英]how to manage 'TabBarView' in flutter?

I tried to make TabBarView in TabBar, but When I put the code below, It became white screen totally and there's nothing and not specific error.. How Çan I solve it?我试图在 TabBar 中制作 TabBarView,但是当我将代码放在下面时,它完全变成了白屏,没有任何内容,也没有具体的错误。我该如何解决? please advice me and appreciate it.请给我建议并感谢它。


class Buttons extends StatefulWidget  {
  const Buttons({Key? key}) : super(key: key);

  @override
  State<Buttons> createState() => _ButtonsState();
}

class _ButtonsState extends State<Buttons> with TickerProviderStateMixin {   //  다중 AnimationController를 사용할 때..???
  @override
  Widget build(BuildContext context)  {
    TabController _tabController   = TabController(length: 3, vsync: this);

    return Container(
      child: Column(
      children: [
        Container(
          child: TabBar(
          controller: _tabController,
          tabs: [
            Tab(icon: ClipRRect(child: Text("Shop"),),),
            Tab(icon: ClipRRect(child: Text("Donate"),),),
            Tab(icon: ClipRRect(child: Text("BId"),),)
          ],
      ),
        ),
         Container(
         // width: double.maxFinite,
         height: 300,
         child: TabBarView(
          controller: _tabController,
          children: [
            ShopPage(),
            DonatePage(),
            BidPage()
          ],
        )
         )
      ])
    );
  }
}

In children, Each pages are in other file and I imported those.在儿童中,每个页面都在其他文件中,我导入了这些文件。

I have checked your code there are some corrections in it I have made it so please try the below code.我已经检查了您的代码,其中有一些更正,所以请尝试以下代码。 I have checked with the below code and it works well.我已经检查了下面的代码,它运行良好。

class Buttons extends StatefulWidget  {
  const Buttons({Key? key}) : super(key: key);

  @override
  State<Buttons> createState() => _ButtonsState();
}

class _ButtonsState extends State<Buttons> with TickerProviderStateMixin {   //  다중 AnimationController를 사용할 때..???
  late TabController _tabController;       

  @override
  Widget build(BuildContext context)  {
     
      

    @override
    void initState() {
      // TODO: implement initState
      super.initState();
      _tabController = TabController(length: 3, vsync: this);
    }

    return Scaffold(
        appBar: AppBar(
          centerTitle: false,
          title: Text(
            'Tabbar Demo',
            style: TextStyle(
                fontSize: 20
            ),
          ),
          bottom: PreferredSize(
            preferredSize: Size.fromHeight(50),
            child: Container(
              child: TabBar(
                controller: _tabController,
                tabs: [
                  Tab(icon: ClipRRect(child: Text("Shop", style: TextStyle(color: Colors.white),),),),
                  Tab(icon: ClipRRect(child: Text("Donate", style: TextStyle(color: Colors.white)),),),
                  Tab(icon: ClipRRect(child: Text("BId", style: TextStyle(color: Colors.white)),),)
                ],
              ),
            ),
          ),
        ),
        body: SafeArea(
          child: Container(
              child: Column(
                  children: [

                    Expanded(
                      child: Container(
                          child: TabBarView(
                            controller: _tabController,
                            children: [
                              Container(color: Colors.red,),
                              Container(color: Colors.black87,),
                              Container(color: Colors.yellow,)
                            ],
                          )
                      ),
                    )
                  ])
          ),
        )
    );
  }
}

Here is the out put from the above code这是上面代码的输出

Let me know if any query让我知道是否有任何疑问

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

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