在 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 (将#修改为@)