inshorts_flutter 0.0.4
inshorts_flutter: ^0.0.4 copied to clipboard
A Flutter package to fetch news from InShorts using its private API. Supports multiple categories and languages.
InShorts Flutter API
Get access to inshorts app's private API in flutter
🌈 Categories #
- All News, Trending, Top Stories
- National, Business, Politics, Sports, Technology
- Startups, Entertainment, Hatke, Education, World
- Automobile, Science, Travel, Miscellaneous, Fashion
🔥 Usage #
Add the dependency in pubspec.yaml:
dependencies:
inshorts_flutter: ^0.0.3
Basic Fetching #
import 'package:inshorts_flutter/inshorts_flutter.dart';
// Fetch news for a specific category
Data newsData = await InShorts.getNews(
newsType: NewsType.allNews,
language: Language.en, // Optional: Language.hi for Hindi
limit: 10 // Optional: default is 10
);
// Access news list
if (newsData.newsList != null) {
for (var news in newsData.newsList!) {
print(news.newsObj?.title);
print(news.newsObj?.content);
}
}
Displaying in a Widget #
FutureBuilder<Data>(
future: InShorts.getNews(newsType: NewsType.trending),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data?.newsList?.length ?? 0,
itemBuilder: (context, index) {
final news = snapshot.data!.newsList![index];
return ListTile(
title: Text(news.newsObj?.title ?? 'No Title'),
subtitle: Text(news.newsObj?.sourceName ?? 'Unknown Source'),
);
},
);
}
return CircularProgressIndicator();
},
)
🏗 Data Models #
Data #
List<News>? newsListString? message
News #
String? hashId,int? rank,NewsObj? newsObj, etc.
NewsObj #
String? title,String? content,String? authorNameString? imageUrl,String? sourceName,String? sourceUrlint? createdAt,List<String>? categoryNames, and more.
✍️ Authors #
- Ashish Pipaliya - Author
📜 License #
This project is licensed under the MIT License.
🧰 Contribution #
Feel free to raise issues and open PRs.