inshorts_flutter 0.0.2 inshorts_flutter: ^0.0.2 copied to clipboard
Inshorts news app's flutter implementation. Inshorts is an app which provides news from different sources and presents them under 60 words. This package uses Inshorts mobile app's private API to bring [...]
import 'package:flutter/material.dart';
import 'package:inshorts_flutter/inshorts_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'InShorts News',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: const HomePage());
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
TabController? _controller;
List categories = [
NewsType.allNews,
NewsType.trending,
NewsType.topStories,
NewsType.business
];
@override
void initState() {
super.initState();
_controller = TabController(length: categories.length, vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('InShorts News'),
bottom: TabBar(
controller: _controller,
tabs: categories
.map((e) => Tab(text: InShorts.getNewsTitle(e)))
.toList())),
body: TabBarView(
controller: _controller,
children: categories
.map((e) => FutureBuilder<Data>(
future: InShorts.getNews(newsType: e, language: Language.en),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data?.newsList?.length ?? 0,
itemBuilder: (context, index) {
News news = snapshot.data!.newsList![index];
return ListTile(
leading: Image.network(news.newsObj!.imageUrl!,
width: 80, fit: BoxFit.fitWidth),
title: Text(news.newsObj!.title!),
subtitle: Text(
news.newsObj!.sourceName!,
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 13),
),
);
},
);
} else if (snapshot.hasError) {
return const Center(child: Text('Errr'));
}
return const Center(child: CircularProgressIndicator());
}))
.toList(),
),
);
}
@override
void dispose() {
_controller?.dispose();
super.dispose();
}
}