reload news

This commit is contained in:
otsmr 2026-07-29 14:14:06 +02:00
parent 5a953226a5
commit 64c7595b6a

View file

@ -19,6 +19,15 @@ class _NewsViewState extends State<NewsView> {
super.initState(); super.initState();
// Mark all as read when entering the page // Mark all as read when entering the page
newsService.markAllAsRead(); newsService.markAllAsRead();
_reloadNews();
}
Future<void> _reloadNews() async {
await newsService.fetchFeed();
await newsService.markAllAsRead();
if (mounted) {
setState(() {});
}
} }
@override @override
@ -29,105 +38,117 @@ class _NewsViewState extends State<NewsView> {
appBar: AppBar( appBar: AppBar(
title: Text(context.lang.settingsHelpNews), title: Text(context.lang.settingsHelpNews),
), ),
body: entries.isEmpty body: RefreshIndicator(
? Center( onRefresh: _reloadNews,
child: Text( child: entries.isEmpty
'No news articles found.', ? SingleChildScrollView(
style: Theme.of(context).textTheme.bodyLarge?.copyWith( physics: const AlwaysScrollableScrollPhysics(),
color: Colors.grey, child: Container(
), height: MediaQuery.of(context).size.height * 0.7,
), alignment: Alignment.center,
) child: Text(
: ListView.builder( 'No news articles found.',
padding: const EdgeInsets.symmetric(vertical: 8), style: Theme.of(context).textTheme.bodyLarge?.copyWith(
itemCount: entries.length, color: Colors.grey,
itemBuilder: (context, index) { ),
final entry = entries[index];
final isDark = isDarkMode(context);
return ReactiveTapFeedback(
onTap: () => launchUrl(
Uri.parse(entry.link),
mode: LaunchMode.externalApplication,
), ),
child: Card( ),
color: isDark ? Colors.grey[800] : Colors.grey[200], )
clipBehavior: Clip.antiAlias, : ListView.builder(
shape: RoundedRectangleBorder( physics: const AlwaysScrollableScrollPhysics(),
borderRadius: BorderRadius.circular(12), padding: const EdgeInsets.symmetric(vertical: 8),
itemCount: entries.length,
itemBuilder: (context, index) {
final entry = entries[index];
final isDark = isDarkMode(context);
return ReactiveTapFeedback(
onTap: () => launchUrl(
Uri.parse(entry.link),
mode: LaunchMode.externalApplication,
), ),
elevation: 0, child: Card(
margin: const EdgeInsets.symmetric( color: isDark ? Colors.grey[800] : Colors.grey[200],
horizontal: 16, clipBehavior: Clip.antiAlias,
vertical: 8, shape: RoundedRectangleBorder(
), borderRadius: BorderRadius.circular(12),
child: Column( ),
crossAxisAlignment: CrossAxisAlignment.stretch, elevation: 0,
children: [ margin: const EdgeInsets.symmetric(
if (entry.imageUrl.isNotEmpty) horizontal: 16,
CachedNetworkImage( vertical: 8,
imageUrl: entry.imageUrl, ),
height: 180, child: Column(
fit: BoxFit.cover, crossAxisAlignment: CrossAxisAlignment.stretch,
placeholder: (context, url) => Container( children: [
if (entry.imageUrl.isNotEmpty)
CachedNetworkImage(
imageUrl: entry.imageUrl,
height: 180, height: 180,
color: Colors.grey.withValues(alpha: 0.1), fit: BoxFit.cover,
), placeholder: (context, url) => Container(
errorWidget: (context, url, error) => Container( height: 180,
height: 180, color: Colors.grey.withValues(alpha: 0.1),
color: Colors.grey.withValues(alpha: 0.1), ),
child: const Icon( errorWidget: (context, url, error) => Container(
Icons.broken_image, height: 180,
size: 50, color: Colors.grey.withValues(alpha: 0.1),
color: Colors.grey, child: const Icon(
Icons.broken_image,
size: 50,
color: Colors.grey,
),
), ),
), ),
), Padding(
Padding( padding: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16), child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ if (entry.pubDate != null) ...[
if (entry.pubDate != null) ...[ Text(
DateFormat.yMMMMd(
Localizations.localeOf(
context,
).toString(),
).format(entry.pubDate!),
style: Theme.of(context).textTheme.bodySmall
?.copyWith(
color: Colors.grey,
),
),
const SizedBox(height: 8),
],
Text( Text(
DateFormat.yMMMMd( entry.title,
Localizations.localeOf(context).toString(), style: Theme.of(context).textTheme.titleLarge
).format(entry.pubDate!),
style: Theme.of(context).textTheme.bodySmall
?.copyWith( ?.copyWith(
color: Colors.grey, fontWeight: FontWeight.bold,
), ),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
], Text(
Text( entry.description,
entry.title, maxLines: 3,
style: Theme.of(context).textTheme.titleLarge overflow: TextOverflow.ellipsis,
?.copyWith( style: Theme.of(context).textTheme.bodyMedium
fontWeight: FontWeight.bold, ?.copyWith(
), color: context.color.onSurface
), .withValues(
const SizedBox(height: 8), alpha: 0.8,
Text( ),
entry.description,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium
?.copyWith(
color: context.color.onSurface.withValues(
alpha: 0.8,
), ),
), ),
), ],
], ),
), ),
), ],
], ),
), ),
), );
); },
}, ),
), ),
); );
} }
} }