EDIT: Question is now Solved
I tried the solution over here but it didn't work out for me.
cases
- I have provided internet permissions
- I am running it on the actual device
- there is an active internet connection on my device
basically, I built an API in python and deployed it on vercel
. now I am trying to fetch details from my API using flutter. the link is https://dailyhunt.vandit.cf/dailyhunt?category=technology
it works fine on web
but doesn't work on an actual device
my code is too long and is separated in multiple files so i can provide with this:
import 'package:news_app/models/article_model.dart';
import 'package:http/http.dart' as http;
import 'package:news_app/constants.dart';
import 'dart:convert';
class News {
List<ArticleModel> news = [];
Future getNews() async {
http.Client client = http.Client();
http.Response response = await client.get(Uri.parse(kDailyhuntEndpoint));
if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['success'] == true) {
jsonData['data'].forEach((element) {
if (element['imageUrl'] != "" && element['content'] != "") {
List<String> raw = element['PublishedTime'].split(" ");
String date = raw[0];
String time = raw[1];
ArticleModel articleModel = ArticleModel(
publishedDate: date,
publishedTime: time,
image: element['imageUrl'].toString(),
content: element['content'].toString(),
fullArticle: element['publisherStory'].toString(),
views: element['viewCount'].toString(),
title: element['title'].toString(),
);
news.add(articleModel);
}
});
} else {
print('ERROR');
}
}
}
}