[英]FutureBuilder widget not returnig the Pages I want - Flutter Firebase
[英]Flutter / Firebase : Refresh FutureBuilder data between pages
我是一名大三学生,我有一个应用程序,用户可以在其中阅读书籍。 我想在应用程序推荐其他书籍的地方添加一个功能。 我使用 Firestore 来存储我的数据。 所以在这里我从 Firestore 获取数据:
Future<List> getMoreChapter() async {
final currentMangaChapters = await FirebaseFirestore.instance
.collection('chapters')
.where('manga', isEqualTo: _currentChapterManga)
.get();
moreChapter.clear();
final currentMangaChaptersList =
currentMangaChapters.docs.map((doc) => doc.data()).toList();
genreReco.addAll(currentMangaChaptersList);
return genreReco;
}
然后我将结果显示到 ListView.builder 和 Future.builder 中:
FutureBuilder(
future: getMoreChapter(),
builder: (context, AsyncSnapshot future) {
if (!future.hasData) {
return Container();
} else {
var moreChaptersList = future.data;
return SizedBox(
height: 140,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: moreChaptersList.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(5),
child: SizedBox(
width: 90,
height: 90,
child: SingleChildScrollView(
child: Column(children: [
Image.network(
moreChaptersList[index]['pic'],
height: 90,
width: 90,
),
const SizedBox(
height: 5,
),
Text(
moreChaptersList[index]['title'],
style: const TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
Text(
'${moreChaptersList[index]['number']}',
style: const TextStyle(fontSize: 10)),
]))));
},
),
);
}
})
它工作正常,但问题是当用户换到另一本书时,应用程序仍然显示以前的推荐。
您可以在底部看到问题。 我认为使用 Future.builder 不是最佳选择。 你有什么建议吗?
好的,所以对于那些想知道的人来说,问题是因为我没有返回好的列表,而是来自其他功能的另一个......
小心点 !
Future<List> getMoreChapter() async {
final currentMangaChapters = await FirebaseFirestore.instance
.collection('chapters')
.where('manga', isEqualTo: _currentChapterManga)
.get();
moreChapter.clear();
final currentMangaChaptersList =
currentMangaChapters.docs.map((doc) => doc.data()).toList();
genreReco.addAll(currentMangaChaptersList);
return currentMangaChaptersList;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.