1、通常创建为AppBar的AppBar.bottom部分并与TabBarView结合使用;也可以与IndexedStack或PageView结合使用
2、如果TabBar 未提供TabController,则必须提供DefaultTabController作为父widget。选项卡控制器的TabController.length必须等于选项卡列表的长度。
const TabBar({
Key key,
@required this.tabs,
this.controller,
this.isScrollable = false,
this.indicatorColor,
this.indicatorWeight = 2.0,
this.indicatorPadding = EdgeInsets.zero,
this.indicator,
this.indicatorSize,
this.labelColor,
this.labelStyle,
this.labelPadding,
this.unselectedLabelColor,
this.unselectedLabelStyle,
})
1、通常与TabBar一起使用。
2、如果未提供TabController,则必须有DefaultTabController 作为父widget
构造函数
const TabBarView({
Key key,
@required this.children,
this.controller,
this.physics,
})
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
@override
State createState() {
return new HomePageState();
}
}
class HomePageState extends State {
@override
List _tabs = [
new Tab(text: "test1",),
new Tab(text: "test2",),
new Tab(text: "test3",),
new Tab(text: "test4",),
new Tab(text: "test5",),
];
List _tabViews = [
new Center(child: new Text("test1",style: new TextStyle(fontSize: 24),),),
new Center(child: new Text("test2",style: new TextStyle(fontSize: 24),),),
new Center(child: new Text("test3",style: new TextStyle(fontSize: 24),),),
new Center(child: new Text("test4",style: new TextStyle(fontSize: 24),),),
new Center(child: new Text("test5",style: new TextStyle(fontSize: 24),),),
];
Widget build(BuildContext context) {
return new DefaultTabController(length: 5, child: new Scaffold(
appBar: new AppBar(
title: new Text("TabBar and TabBarView"),
bottom: new TabBar(tabs: _tabs,
indicator: new BoxDecoration(image: new DecorationImage(image: NetworkImage("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3260609003,3965213395&fm=27&gp=0.jpg"))),
)
,
),
body: new TabBarView(children: _tabViews),
));
}
}