Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NewsWidget extends StatelessWidget {
- const NewsWidget({
- super.key,
- required this.news,
- });
- final Future news;
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 8.0),
- child: SizedBox(
- child: FutureBuilder(
- future: news,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return Column(
- children: snapshot.data.map<Widget>(
- (item) {
- return Card(
- elevation: 3,
- color: Colors.white,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Row(
- children: [
- Icon(
- Icons.article_outlined,
- color: Colors.red,
- ),
- Expanded(
- child: ListTile(
- title: Text(
- item.title,
- style: TextStyle(
- fontFamily: 'Poppins',
- fontWeight: FontWeight.w500,
- ),
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- ),
- subtitle: Text(
- DateTime.fromMillisecondsSinceEpoch(
- item.timestamp!)
- .toString(),
- style: TextStyle(
- fontFamily: 'Poppins',
- fontWeight: FontWeight.w300,
- ),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ),
- InkWell(
- child: Icon(
- Icons.arrow_forward_ios_outlined,
- color: Colors.red,
- ),
- onTap: () {
- print('${item.title} tapped.');
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => NewsScreen(),
- ),
- );
- },
- ),
- ],
- ),
- ),
- );
- },
- ).toList(),
- );
- } else if (snapshot.hasError) {
- return Text('${snapshot.error}');
- }
- return const CircularProgressIndicator();
- },
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment