【发布时间】:2020-10-21 18:49:18
【问题描述】:
我的颤振应用有问题。我刚刚在我的列表视图中调用了一些小部件。我的小部件使用 Api Data(http,futurebuilder)。但是当我向上或向下滚动时,我的小部件会重新呈现或调用。我把所有的 api 方法都称为 initstate()。
我不明白,有什么问题?
HomeScreen.dart:
...
ListView(
children: <Widget>[
MainHeadlineMod(),
SizedBox(
height: 30.0,
),
CategoryMod(
categoryId: 19,
),
SizedBox(
height: 30.0,
),
CategoryMod(
categoryId: 15,
),
SizedBox(
height: 30.0,
),
CategoryMod(
categoryId: 20,
),
SizedBox(
height: 30.0,
),
CategoryMod(
categoryId: 14,
),
SizedBox(
height: 30.0,
),
CategoryMod(
categoryId: 16,
),
],
),
...
CategoryMod.dart:
...
class _CategoryModState extends State<CategoryMod> {
final WebService ws = WebService();
Future<List<ShortNewsModel>> _futureCategoryNews;
@override
void initState() {
_futureCategoryNews = ws.fetchCategoryNews(widget.categoryId);
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
child: FutureBuilder<List<ShortNewsModel>>(
future: _futureCategoryNews,
builder: (context, snapshot) {
if (snapshot.hasData) {
...
【问题讨论】: