启动应用程序时如何直接获取网络数据?

时间:2019-01-12 09:03:45

标签: asynchronous networking dart flutter

我正在使用Bloc模式实现Youtube Clone App。现在,我正在获取视频的缩略图,并根据该图像创建ListView。

启动应用后,我想直接从Internet加载3张图像,但是当我在initState()函数中编写该代码时,它不起作用。

      @override
    void initState() {
      super.initState();
      _getVideo();
      _getVideo();  
      _getVideo();
      _scrollController.addListener((){
        if(_scrollController.position.pixels == _scrollController.position.maxScrollExtent){
          _getVideo();
        }
      });
    }

  @override
    void dispose() {
      _scrollController.dispose();
      _youtubeBloc.dispose();
      super.dispose();
    }

  Future<void> _getVideo() async {
    VideoModel model = await _youtubeApi.getChannelVideo(index);
    _youtubeBloc.addChannelData(model);
    index++;
  }

initState()函数中,我多次调用_getVideo()方法,但是它无法从Internet提取数据,所以我的问题是启动应用程序后如何直接从网络获取数据? / p>

0 个答案:

没有答案