Fetching multiple RSS feeds in Flutter

425 views
Skip to first unread message

Dotnaught

unread,
Oct 23, 2020, 10:23:57 PM10/23/20
to Flutter Development (flutter-dev)

If anyone has any idea how I might turn this code to fetch a single RSS feed in a Flutter app into code that can handle a set of different RSS feeds, I'd be grateful for the help. 

class RSSFetch { 
  final _targetUrl = 'feed.rss'; 
 Future<Rss1Feed> getFeed() => http.read(_targetUrl).then((xmlString) => Rss1Feed.parse(xmlString)); }

The above works fine for a single feed but I want to pulls multiple RSS feeds and combined them before returning them? I assume it would involve a Future.wait but I'm stuck on the syntax (the example below isn't right).

As an additional complication, it looks like the Dart RSS library (webfeed or its fork dart_rss) requires you to invoke a different parsing object for each RSS format (RSS 1.0. 2.0, and Atom).


...this is wrong but I assume it's something like this...

class RSSFetch { 
  List<String> urlList = [ 'feed.rss', 'feed2.rss' ]; 

 Future<Rss1Feed> getFeed() { 
  List<Rss1Feed> list = await Future.wait(urlList.map((item) { http.read(item).then((xmlString) => Rss1Feed.parse(xmlString)); 
 } )); 

  return list; //need to return RSS1Feed, RSS2Feed, or AtomFeed, and all feeds normalized
 } 

Suzuki Tomohiro

unread,
Oct 23, 2020, 11:13:11 PM10/23/20
to Flutter Development (flutter-dev)
(I don't know anything about RSS1, or Atom. So let me focus on the Future part)
How about something like this? (I didn't run this; so it contains errors)
Ensure you declare all variables with types including Future<X>. Types clarify syntax errors.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/8745a8c8-0efe-4b0b-857c-10f361f7a936n%40googlegroups.com.

Dotnaught

unread,
Oct 24, 2020, 12:17:29 PM10/24/20
to Flutter Development (flutter-dev)
Thanks. That's helpful.

List<Rss1Feed> list = await Future.wait(futures);
return list;

That bit generates an error: 
NoSuchMethod: Class List<Rss1Feed> has not instance of getter 'items.' Receiver: Instance (length: 2) of '_GrowableList'

I suspect my approach is ill-advised given the limits of the Dart RSS library, which doesn't automatically handle each of the three types of RSS feed formats. It may end up being better to just fetch the feeds, put the items in widgets and then sort the list of widgets rather than try to combine all the RSS feeds into a single list before putting the entries into a list of widgets.

Suzuki Tomohiro

unread,
Oct 24, 2020, 12:38:42 PM10/24/20
to Flutter Development (flutter-dev)
I don’t see any reference to “item” field. Set breakpoints inside downloadAndParseFeed function. It clarifies which method is throwing the error. Very likely it’s Rss1Feed.parse() method and I think your analysis is correct; the library is not supporting the feed’s format.

> put the items in widgets and then sort the list of widgets

When you sort them, I think you want to sort the feeds by their contents (last update or title). The content is only available after parsing them.


Reply all
Reply to author
Forward
0 new messages