在此扩展平铺列表代码示例中:
我的列表来自于API,每个ExpansionTile都包含一些ListTile。如何实现ListTile像ExpansionTile一样?
使用列表视图显示ListTile中的所有项目。
import 'package:flutter/material.dart';
import 'package:flutter_expansion_tile_demo/Constants/Constants.dart';
import 'package:flutter_expansion_tile_demo/model/month_model.dart';
class ExpansionTileDemo extends StatefulWidget {
@override
_ExpansionTileDemoState createState() => _ExpansionTileDemoState();
}
class _ExpansionTileDemoState extends State<ExpansionTileDemo> {
List<MonthModel> monthModel;
@override
void initState() {
monthModel = Constants.getMonthModel();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Expansion Tile Demo'),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: BouncingScrollPhysics(),
itemCount: monthModel.length,
itemBuilder: (BuildContext context, int index) {
return _buildPlayerModelList(monthModel[index]);
},
),
),
);
}
Widget _buildPlayerModelList(MonthModel items) {
return Card(
child: ExpansionTile(
title: Text(
items.playerName,
style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500),
),
children: <Widget>[
ListTile(
title: Text(
items.description,
style: TextStyle(fontWeight: FontWeight.w700),
),
)
],
),
);
}
}
这个图像输出代码,但我想更多的ListTile?我怎么能做这项工作?
谢谢你帮我
1条答案
按热度按时间mf98qq941#
首先你需要改变你的
MonthModel
类,使description
成为List of string,然后把你的_buildPlayerModelList
改为: