当我尝试使用DefaultTabController()小部件时,我在Flutter中遇到了这个问题,但是它似乎无法按照我指定的布局工作。谁能帮助我。
这是我的代码:
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
initialIndex: 0,
child: Scaffold(
appBar: AppBar(
leading: IconButton(icon: Icon(Icons.menu), onPressed: () {}),
title: Text('Home'),
bottom: TabBar(tabs: [
Tab(child: Text("Videos")),
Tab(child: Text("Live Videos")),
Tab(child: Text("Gallery")),
]),
),
body: TabBarView(
children: [
new Card(
color: Colors.blue,
),
],
),
));
}
}
我在这里做错了什么?
您的body元素仅包含一个元素。根据您的DefaultTabController的length属性,该数组中应该有3个元素。
body: TabBarView(
children: [
new Card(
color: Colors.blue,
),
new Card(
color: Colors.red,
),
new Card(
color: Colors.orange,
),
],
),