Allow CORS Headers / Flutter

346 views
Skip to first unread message

Bridget Kelly O'Sheehan

unread,
Mar 1, 2021, 2:20:21 AM3/1/21
to Flutter Development (flutter-dev)
Hi,

I'm building a mobile application for my client and I would simply like to be able to pull their news feed in from their server at https://audiodamage.co.uk/feed/ (This is from WordPress).

I've tried a few times and it won't let me do this, can anyone advise if I should need to place any cors header on the server to allow this to pull the information from the server side also whether this would work?

or would it just be better if I built a web application and hosted it on that server and then pulled into the mobile application?

Any information, would be greatly appreciated. 

Kindest Regards,

Bridget


'''''
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://audiodamage.co.uk/feed/';
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 {
http.Response response = await http.get(
headers: {'Accept': "application/json"});
return RssFeed.parse(response.body);
print(response.body);
}

''''''




Manish Vlog

unread,
Mar 1, 2021, 3:44:07 AM3/1/21
to Bridget Kelly O'Sheehan, Flutter Development (flutter-dev)
You can ask our expert on chat for app solutions. 

--
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/50768e57-5088-4429-8fde-95d5e51c8d5bn%40googlegroups.com.

EthicCoders Apps

unread,
Mar 1, 2021, 4:52:24 AM3/1/21
to Bridget Kelly O'Sheehan, Flutter Development (flutter-dev)
I just tried with the link that you provided. I was able to get the rss response & parse it. 
The package that we used is webfeed.

And the code snippet for our network class is given below. Try it out and let us know if it works or what error you get: 

...
import 'package:webfeed/webfeed.dart';
import 'package:http/http.dart' as http;
class Network {
Network();

var httpClient = new http.Client();

Future<RssFeed> getRssFeed(String feedlink) async {
//debug
//feedlink = 'https://audiodamage.co.uk/feed/';

try {
// RSS feed
Response response = await httpClient.get(feedlink);
AppUtils.printDebug(response.body);
return RssFeed.parse(response.body);
}catch(e) {
AppUtils.printDebug(e.toString());
throw Exception('Failed to getRssFeed');
}
}
}

Reply all
Reply to author
Forward
0 new messages