我想在 Flutter 中使用 ListView.itembuilder 显示多个 ListTiles。我做到了,但屏幕仍然是空白的。尝试了热重载以及两次运行该应用程序。代码有什么问题?
PS:列表将出现在我之前创建的 TabBarView 中。还发布了 TabBarView 的截图。
列表视图代码:
class SportBets extends StatefulWidget {
@override
_SportBetsState createState() => _SportBetsState();
}
class _SportBetsState extends State<SportBets> {
final sportList = [
"Basketball",
"Football",
"Volleyball",
];
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: sportList.length,
itemBuilder: (context, index){
ListTile(
title: Text(sportList[index], style: TextStyle(fontSize: 20.0, color: Colors.black),),
trailing: IconButton(
icon: Icon(Icons.arrow_forward_ios),
color: Colors.blue,
onPressed: (){}
),
leading: CircleAvatar(child: Icon(Icons.wb_sunny),radius: 18.0,),
);
}
);
}
}
TabBarView 代码:
body: TabBarView(
children: <Widget>[
Center(
child: Text(
"Highlights Page here",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
),
Center(
child: Text(
"Casino Page here",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
),
Center(
child: Text(
"Promotions Page here",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
),
SportBets(),
],
),