美文网首页
分享代码

分享代码

作者: Victory_886 | 来源:发表于2019-08-15 15:05 被阅读0次
        Widget _defalutTabController() {
          Widget _tabBarCell(Color col) {
            return Container(
              child: Expanded(
                child: Container(
                  color: MusicColors.slRandomColor(),
                  margin: EdgeInsets.all(10),
                ),
              ),
            );
          }
    
          List<Widget> _tabBarRowChildrenList = <Widget>[
            _tabBarCell(Colors.blue),
            _tabBarCell(Colors.yellow),
            _tabBarCell(Colors.black),
            _tabBarCell(Colors.orange),
          ];
    
          Widget _tabBarPageView(Color col) {
            return Container(
              margin: EdgeInsets.only(top: 35, left: 10, right: 10, bottom: 10),
              padding: EdgeInsets.all(2),
              color: col, //MusicColors.slRandomColor(),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: _tabBarRowChildrenList,
              ),
            );
          }
    
          List<Widget> _tabBarViewChildrenList = <Widget>[
            _tabBarPageView(Colors.purple),
            _tabBarPageView(Colors.yellow),
            _tabBarPageView(Colors.orange),
          ];
    
          Widget _tabbarView() {
            return TabBarView(
              physics: NeverScrollableScrollPhysics(),
              children: _tabBarViewChildrenList,
            );
          }
    
          _totalPageCount = _tabBarViewChildrenList.length;
    
          return DefaultTabController(
            length: _totalPageCount,
            child: Builder(
              builder: (BuildContext context) => Padding(
                padding: EdgeInsets.all(8.0),
                child: Container(
                  color: Colors.red,
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: IconButton(
                            tooltip: "上\n一\n页",
                            icon: Icon(Icons.arrow_back_ios),
                            onPressed: () {
                              final TabController _controller =
                                  DefaultTabController.of(context);
                              if (_controller.index > 0) {
                                _controller.animateTo(_controller.index - 1);
                                setState(() {
                                  _pageIndex = _controller.index;
                                });
                                print("object = $_pageIndex");
                              } else {
                                print("已经是第一页了");
                              }
                            }),
                      ),
                      Expanded(
                        child: Container(
                          // child: _tabbarView(),
                          // child: _listView(),
                          color: Colors.black45,
                        ),
                      ),
                      Container(
                        child: IconButton(
                          tooltip: "下\n一\n页",
                          icon: Icon(Icons.arrow_forward_ios),
                          onPressed: () {
                            final TabController _controller =
                                DefaultTabController.of(context);
                            print("_____${_controller.index}");
                            if (_controller.index != _totalPageCount - 1) {
                              _controller.animateTo(_controller.index + 1);
                              setState(() {
                                _pageIndex = _controller.index;
                              });
                              print("object = $_pageIndex");
                            } else {
                              print("final page");
                            }
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          );
        }
    
    

    相关文章

      网友评论

          本文标题:分享代码

          本文链接:https://www.haomeiwen.com/subject/ksyzjctx.html