当我在 flutter 中打开视图时,缩略图不显示

问题描述 投票:0回答:1

我正在尝试显示视频的缩略图,我正在从 firebase 获取缩略图 url 并使用 Image.network 来显示它们,但缩略图不会在第一次显示时显示,只有当我热重载时才会出现 我这样调用 fetch ThumbnailUrls

class _XtreamTubeState extends State<XtreamTube> {
  @override
  void initState() {
    super.initState();
    _fetchThumbnailUrls();
  }

我像这样显示缩略图

  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          const CustomSliverTubeAppBar(),
          SliverList(
              delegate: SliverChildBuilderDelegate(
            (context, index) {
              final video = thumbnailUrl[index];
              print('video$video');
              return VideoContainer(videoUrl: video);
            },
            childCount: thumbnailUrl.length,
          ))
        ],
      ),
    );
  }

我尝试了很多事情

flutter firebase thumbnails video-thumbnails
1个回答
0
投票

我认为在构建中,thumbnailUrl 列表不应该为空,这会导致渲染不正确
所以试试这个

Widget build(BuildContext context) {
  if (thumbnailUrl.isEmpty) {
    return ProgressIndicator(); // <--pass something to keep in rendering 
                                //untill thumbnailUrl.isEmpty is false
  } else {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          const CustomSliverTubeAppBar(),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) {
                final video = thumbnailUrl[index];
                print('video$video');
                return VideoContainer(videoUrl: video);
              },
              childCount: thumbnailUrl.length,
            ),
          ),
        ],
      ),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.