4
4
import 'package:flutter/foundation.dart' show kIsWeb; // Import kIsWeb
5
5
import 'package:flutter/material.dart' ;
6
6
import 'package:flutter_bloc/flutter_bloc.dart' ;
7
+ import 'package:go_router/go_router.dart' ; // Import GoRouter
7
8
import 'package:ht_main/account/bloc/account_bloc.dart' ; // Import AccountBloc
8
9
import 'package:ht_main/headline-details/bloc/headline_details_bloc.dart' ; // Import BLoC
9
10
import 'package:ht_main/headline-details/bloc/similar_headlines_bloc.dart' ; // Import SimilarHeadlinesBloc
@@ -73,10 +74,6 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
73
74
listenWhen: (previous, current) {
74
75
final detailsState = context.read <HeadlineDetailsBloc >().state;
75
76
if (detailsState is HeadlineDetailsLoaded ) {
76
- if (current.status == AccountStatus .failure &&
77
- previous.status != AccountStatus .failure) {
78
- return true ;
79
- }
80
77
final currentHeadlineId = detailsState.headline.id;
81
78
final wasPreviouslySaved =
82
79
previous.preferences? .savedHeadlines.any (
@@ -88,9 +85,21 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
88
85
(h) => h.id == currentHeadlineId,
89
86
) ??
90
87
false ;
91
- return (wasPreviouslySaved != isCurrentlySaved) ||
92
- (current.status == AccountStatus .success &&
93
- previous.status != AccountStatus .success);
88
+
89
+ // Condition 1: Actual change in saved status for this headline
90
+ if (wasPreviouslySaved != isCurrentlySaved) {
91
+ // Only trigger if the status is success (to show confirmation)
92
+ // or failure (to show error). Avoid triggering if status is just loading.
93
+ return current.status == AccountStatus .success ||
94
+ current.status == AccountStatus .failure;
95
+ }
96
+
97
+ // Condition 2: A specific save/unsave operation just failed
98
+ // This triggers if an operation was attempted (loading) and then failed.
99
+ if (current.status == AccountStatus .failure &&
100
+ previous.status == AccountStatus .loading) {
101
+ return true ;
102
+ }
94
103
}
95
104
return false ;
96
105
},
@@ -487,7 +496,15 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
487
496
),
488
497
child: HeadlineItemWidget (
489
498
headline: similarHeadline,
490
- targetRouteName: Routes .articleDetailsName,
499
+ // Use the onTap callback for navigation
500
+ onTap: (tappedHeadline) {
501
+ context.pushNamed (
502
+ Routes .articleDetailsName,
503
+ pathParameters: {'id' : tappedHeadline.id},
504
+ extra: tappedHeadline,
505
+ );
506
+ },
507
+ // targetRouteName: Routes.articleDetailsName, // No longer needed here
491
508
),
492
509
);
493
510
},
0 commit comments