Flutter RSS Feed XML Request Error Issue

94 views
Skip to first unread message

Bridget Kelly O'Sheehan

unread,
Feb 18, 2021, 9:49:53 AM2/18/21
to Flutter Development (flutter-dev)
Hi, 

Can anyone advise to why i'm getting this issue?
 You can also find this presented better on 
stack


any help would be appreciated.


```
import 'package:ad/main.dart'; import 'package:flutter/material.dart'; import 'dart:async'; import 'package:webfeed/webfeed.dart'; import 'package:http/http.dart' as http; import 'package:url_launcher/url_launcher.dart'; import 'package:cached_network_image/cached_network_image.dart'; class NewsFeed extends StatefulWidget { NewsFeed() : super(); final String title = 'RSS Feed'; @override NewsFeedState createState() => NewsFeedState(); } class NewsFeedState extends State<NewsFeed> { static const String FEED_URL = 'https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss'; RssFeed _feed; String _title; static const String loadingFeedMsg = 'Loading Feed...'; static const String feedLoadErrorMsg = 'Error Loading Feed...'; static const String feedOpenErrorMsg = 'Error Opening Feed...'; static const String placeholderImg = 'images/no_image.png'; GlobalKey<RefreshIndicatorState> _refreshKey; updateTitle(title) { setState(() { _title = title; }); } updateFeed(feed) { setState(() { _feed = feed; }); } Future<void> openFeed(String url) async { if (await canLaunch(url)) { await launch( url, forceSafariVC: true, forceWebView: false, ); return; } updateTitle(feedOpenErrorMsg); } load() async { updateTitle(loadingFeedMsg); loadFeed().then((result) { if (null == result || result.toString().isEmpty) { updateTitle(feedLoadErrorMsg); return; } updateFeed(result); updateTitle(_feed.title); }); } Future<RssFeed> loadFeed() async { try { final client = http.Client(); final response = await client.get(FEED_URL); return RssFeed.parse(response.body); } catch (e) { print(e); // handle any exceptions here } return null; } @override void initState() { super.initState(); _refreshKey = GlobalKey<RefreshIndicatorState>(); updateTitle(widget.title); load(); } title(title) { return Text( title, style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w500), maxLines: 2, overflow: TextOverflow.ellipsis, ); } subtitle(subTitle) { return Text( subTitle, style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w100), maxLines: 1, overflow: TextOverflow.ellipsis, ); } thumbnail(imageUrl) { return Padding( padding: EdgeInsets.only(left: 15.0), child: CachedNetworkImage( placeholder: (context, url) => Image.asset(placeholderImg), imageUrl: imageUrl, height: 50, width: 70, alignment: Alignment.center, fit: BoxFit.fill, ), ); } rightIcon() { return Icon( Icons.keyboard_arrow_right, color: Colors.grey, size: 30.0, ); } list() { return ListView.builder( itemCount: _feed.items.length, itemBuilder: (BuildContext context, int index) { final item = _feed.items[index]; //return ListTile( return ListTile( title: title(item.title), //subtitle: subtitle(item.description), subtitle: subtitle(item.description), leading: item.enclosure?.url != null ? thumbnail(item.enclosure.url) : SizedBox.shrink(), // Replace Container() with SizedBox.shrink() trailing: rightIcon(), contentPadding: EdgeInsets.all(5.0), onTap: () => openFeed(item.link), ); }, ); } isFeedEmpty() { return null == _feed || null == _feed.items; } body() { return isFeedEmpty() ? Center( child: CircularProgressIndicator(), ) : RefreshIndicator( key: _refreshKey, child: list(), onRefresh: () => load(), ); } // ///////////////////////////////////////////////// @override Widget build(BuildContext context) { return Scaffold( drawer: DrawerCodeOnly(), appBar: AppBar( title: Text(_title), ), body: body(), ); } }

```

Andy Greenshaw

unread,
Feb 18, 2021, 10:16:24 AM2/18/21
to Flutter Development (flutter-dev), Bridget Kelly O'Sheehan
Is this on web? You don’t give much to help - erroryou get and stack trace...

You’re probably getting a CORS error at using this ‘CachedNetworkImage'
--
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/b7f29dfe-2961-406a-8433-28daeb21d7c8n%40googlegroups.com.

Bridget Kelly O'Sheehan

unread,
Feb 18, 2021, 10:23:11 AM2/18/21
to Flutter Development (flutter-dev)
Hi Andy,

Thanks for responding, I've edited the post on stack which shows a picture in Visual Studio debugger and this is all it shows.

Screenshot 2021-02-18 at 15.20.16.png

Bridget Kelly O'Sheehan

unread,
Feb 18, 2021, 10:23:58 AM2/18/21
to Flutter Development (flutter-dev)
Sorry, forgot to mention, it is on the Web, but I do get the same issue while running on in mobile simulation. I did wonder if it could be related to CORS

Andy Greenshaw

unread,
Feb 18, 2021, 10:29:44 AM2/18/21
to Flutter Development (flutter-dev), Bridget Kelly O'Sheehan
Try running it from the command line (in the root directory of the project) like this 
flutter run -d chrome --web-renderer html

Does it work now? If yes, CORS issue.

Bridget Kelly O'Sheehan

unread,
Feb 18, 2021, 10:57:40 AM2/18/21
to Flutter Development (flutter-dev)
Screenshot 2021-02-18 at 15.55.43.png
Ran the command and same issue :(
On Thursday, 18 February 2021 at 15:16:24 UTC andy...@gmail.com wrote:

Andy Greenshaw

unread,
Feb 18, 2021, 12:02:39 PM2/18/21
to Bridget Kelly O'Sheehan, Flutter Development (flutter-dev)
Definitely CORS. If I run fetching an rss feed from the same server as the web page is running on, works fine.

Reply all
Reply to author
Forward
0 new messages