微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Flutter 应用程序中使用带有 webfeed 包的 RSS 时,getter 'items' 被调用为 null

如何解决在 Flutter 应用程序中使用带有 webfeed 包的 RSS 时,getter 'items' 被调用为 null

我想在新闻应用项目中使用 webFeed 包。我可以获得 RSSFeed 对象,我可以构建一个 ListView 小部件,其中包含 RSSFeed.items 列表中每个项目的标题和图像。但是当应用程序开始加载新闻时出现问题,我收到此错误消息。如果我热重新加载应用程序,它工作正常。我的负载提要功能未来类型。我不擅长使用状态管理。我尝试使用 mobx 包,但找不到解决方案。有什么建议吗?

════════ Exception caught by widgets library ════════
The getter 'items' was called on null.
Receiver: null
Tried calling: items
  @observable
 final String title = 'News';
  @observable
 RSSFeed _RSSFeed;


 @action
Future<void>openFeed(String url) async{
if(await canLaunch(url) ){

  await launch(
      url,forceSafariVC:true,forceWebView:false,);
  return;
}

updateTitle(FeedLoadErrorMsg);
}

@action
load() async {
updateTitle(loadingFeedMsg);
loadFeed().then((result){
    if(result==null || result.toString().isEmpty){
      updateTitle(FeedLoadErrorMsg);
      return;
    }
    updateFeed(result);
    updateTitle(_RSSFeed.title);

});
}
@action
Future<RSSFeed> loadFeed() async{
try{
  final client= http.Client();
  final response=await client.get(Feed_URL);

  var RSSFeed= RSSFeed.parse(response.body.toString());
 // var atomFeed = AtomFeed.parse(response.body);

  print("Url Imagen: " + RSSFeed.items[0].imageUrl);
  return RSSFeed;
 }
catch(e){
    print("Load Feed does not work ! ");
 }
return null;
}

@override
void initState() {
// Todo: implement initState
super.initState();
_refreshKey=GlobalKey<RefreshindicatorState>();
updateTitle(widget.title);
load();
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。