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();
// Mark all as read when entering the page
newsService.markAllAsRead();
_reloadNews();
}
Future<void> _reloadNews() async {
await newsService.fetchFeed();
await newsService.markAllAsRead();
if (mounted) {
setState(() {});
}
}
@override
@ -29,16 +38,24 @@ class _NewsViewState extends State<NewsView> {
appBar: AppBar(
title: Text(context.lang.settingsHelpNews),
),
body: entries.isEmpty
? Center(
body: RefreshIndicator(
onRefresh: _reloadNews,
child: entries.isEmpty
? SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Container(
height: MediaQuery.of(context).size.height * 0.7,
alignment: Alignment.center,
child: Text(
'No news articles found.',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Colors.grey,
),
),
),
)
: ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.symmetric(vertical: 8),
itemCount: entries.length,
itemBuilder: (context, index) {
@ -91,7 +108,9 @@ class _NewsViewState extends State<NewsView> {
if (entry.pubDate != null) ...[
Text(
DateFormat.yMMMMd(
Localizations.localeOf(context).toString(),
Localizations.localeOf(
context,
).toString(),
).format(entry.pubDate!),
style: Theme.of(context).textTheme.bodySmall
?.copyWith(
@ -114,7 +133,8 @@ class _NewsViewState extends State<NewsView> {
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium
?.copyWith(
color: context.color.onSurface.withValues(
color: context.color.onSurface
.withValues(
alpha: 0.8,
),
),
@ -128,6 +148,7 @@ class _NewsViewState extends State<NewsView> {
);
},
),
),
);
}
}