在颤动中水平滑动标签栏

时间:2019-09-18 05:54:35

标签: flutter dart

我的Flutter应用程序代码中有类似的内容,我无法在选项卡中水平滑动,您能帮我解决错误的地方吗?

getBody(var data) {
    double maxHeight = MediaQuery.of(context).size.height;
    developer.log('Max height:' + maxHeight.toString());
    return Column(
      children: <Widget>[
        Container(
          child: TabBar(
            labelColor: Colors.black,
            tabs: [
              new Tab(text: 'Credit', icon: new Icon(Icons.list)),
              new Tab(text: 'Debit', icon: new Icon(Icons.pie_chart)),
              new Tab(text: 'Online', icon: new Icon(Icons.insert_chart)),
            ],
            controller: _tabController,
            onTap: _handleTabSelection,
          ),
        ),
        Container(
          margin: new EdgeInsets.all(0.0),
          height: maxHeight - 229,
          child: new Center(
            child: new RefreshIndicator(
              onRefresh: refreshList,
              child: createReportList(context, data),
            ),
          ),
        ),
      ],
    );
  }

代码输出为, The result of the above code, I have to click on each tab, sliding is not coming

1 个答案:

答案 0 :(得分:0)

请尝试一下。

@override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 6,
      child: Scaffold(
          appBar: AppBar(
            centerTitle: true,
            leading: Icon(Icons.person_outline),
            title: Text(‘HOME SCREEN',style: TextStyle(fontSize: 16.0),),
            bottom: PreferredSize(
                child: TabBar(
                    isScrollable: true,
                    unselectedLabelColor: Colors.white.withOpacity(0.3),
                    indicatorColor: Colors.white,
                    tabs: [
                      Tab(
                        child: Text(‘Kumar'),
                      ),
                      Tab(
                        child: Text(‘Lokesh'),
                      ),
                      Tab(
                        child: Text(‘Rathod'),
                      ),
                      Tab(
                        child: Text(‘Raj'),
                      ),
                      Tab(
                        child: Text(’Madan'),
                      ),
                      Tab(
                        child: Text(‘Manju'),
                      )
                    ]),
                preferredSize: Size.fromHeight(30.0)),
            actions: <Widget>[
              Padding(
                padding: const EdgeInsets.only(right: 16.0),
                child: Icon(Icons.add_alert),
              ),
            ],
          ),
          body: TabBarView(
            children: <Widget>[
              Container(
                child: Center(
                  child: Text('Tab 1'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 2'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 3'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 4'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 5'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 6'),
                ),
              ),
            ],
          )),
    );
  }