import 'package:didvan/models/overview_data.dart'; import 'package:didvan/models/requests/news.dart'; import 'package:didvan/routes/routes.dart'; import 'package:didvan/utils/date_time.dart'; import 'package:didvan/views/home/widgets/bookmark_button.dart'; import 'package:didvan/views/widgets/didvan/card.dart'; import 'package:didvan/views/widgets/didvan/divider.dart'; import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:didvan/views/widgets/shimmer_placeholder.dart'; import 'package:didvan/views/widgets/skeleton_image.dart'; import 'package:flutter/material.dart'; class NewsOverview extends StatelessWidget { final OverviewData news; final NewsRequestArgs? newsRequestArgs; final void Function(int id, bool value, bool shouldUpdate) onMarkChanged; final bool hasUnmarkConfirmation; const NewsOverview({ Key? key, required this.news, required this.onMarkChanged, this.newsRequestArgs, this.hasUnmarkConfirmation = false, }) : super(key: key); @override Widget build(BuildContext context) { return DidvanCard( onTap: () => Navigator.of(context).pushNamed( Routes.newsDetails, arguments: { 'onMarkChanged': (id, value) => onMarkChanged(id, value, true), 'id': news.id, 'args': newsRequestArgs, 'hasUnmarkConfirmation': hasUnmarkConfirmation, }, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ SkeletonImage( imageUrl: news.image, width: 64, height: 64, ), const SizedBox(width: 8), Expanded( child: SizedBox( height: 64, child: DidvanText( news.title, style: Theme.of(context).textTheme.bodyText1, ), ), ), ], ), const SizedBox(height: 8), DidvanText( news.description, maxLines: 3, ), const DidvanDivider(verticalPadding: 8), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ DidvanText( news.reference!, style: Theme.of(context).textTheme.caption, ), DidvanText( ' - ' + DateTimeUtils.momentGenerator(news.createdAt), style: Theme.of(context).textTheme.caption, ), ], ), BookmarkButton( itemId: news.id, type: 'news', gestureSize: 32, value: news.marked, onMarkChanged: (value) => onMarkChanged(news.id, value, false), askForConfirmation: hasUnmarkConfirmation, ), ], ), ], ), ); } static Widget get placeholder => DidvanCard( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ const ShimmerPlaceholder(height: 64, width: 64), const SizedBox(width: 8), Column( crossAxisAlignment: CrossAxisAlignment.start, children: const [ ShimmerPlaceholder(height: 18, width: 200), SizedBox(height: 8), ShimmerPlaceholder(height: 18, width: 100), ], ), ], ), const SizedBox(height: 12), const ShimmerPlaceholder( height: 16, width: double.infinity, ), const SizedBox(height: 8), const ShimmerPlaceholder( height: 16, width: double.infinity, ), const SizedBox(height: 8), const ShimmerPlaceholder( height: 16, width: 100, ), const DidvanDivider(verticalPadding: 8), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: const [ ShimmerPlaceholder(height: 12, width: 150), ShimmerPlaceholder(height: 24, width: 24), ], ), ], ), ); }