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");
}
},
),
),
],
),
),
),
),
);
}
网友评论