Skip to content

Search page routing bug #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/headlines-feed/view/headlines_feed_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
}
// Otherwise, build the headline item
final headline = state.headlines[index];
return HeadlineItemWidget(headline: headline);
return HeadlineItemWidget(
headline: headline,
targetRouteName: Routes.articleDetailsName,
);
},
),
);
Expand Down
11 changes: 9 additions & 2 deletions lib/headlines-feed/widgets/headline_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import 'package:intl/intl.dart'; // For date formatting
/// A widget that displays a single headline with enhanced styling.
class HeadlineItemWidget extends StatelessWidget {
/// Creates a [HeadlineItemWidget].
const HeadlineItemWidget({required this.headline, super.key});
const HeadlineItemWidget({
required this.headline,
required this.targetRouteName, // Add targetRouteName
super.key,
});

/// The headline to display.
final Headline headline;

/// The named route to navigate to when the item is tapped.
final String targetRouteName; // Add targetRouteName

// Helper for date formatting
static final _dateFormatter = DateFormat.yMd().add_jm();

Expand All @@ -38,7 +45,7 @@ class HeadlineItemWidget extends StatelessWidget {
child: InkWell(
onTap: () {
context.goNamed(
Routes.articleDetailsName,
targetRouteName, // Use the new parameter here
pathParameters: {'id': headline.id},
);
},
Expand Down
6 changes: 5 additions & 1 deletion lib/headlines-search/view/headlines_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ht_main/headlines-feed/widgets/headline_item_widget.dart';
import 'package:ht_main/router/routes.dart'; // Import Routes
import 'package:ht_main/headlines-search/bloc/headlines_search_bloc.dart';
import 'package:ht_main/l10n/l10n.dart';
import 'package:ht_main/shared/constants/app_spacing.dart'; // Import AppSpacing
Expand Down Expand Up @@ -216,7 +217,10 @@ class _HeadlinesSearchViewState extends State<_HeadlinesSearchView> {
);
}
// Display headline item
return HeadlineItemWidget(headline: headlines[index]);
return HeadlineItemWidget(
headline: headlines[index],
targetRouteName: Routes.searchArticleDetailsName,
);
},
),
// Default case (should ideally not be reached if states are handled)
Expand Down
18 changes: 18 additions & 0 deletions lib/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,24 @@ GoRouter createRouter({
path: Routes.search, // '/search'
name: Routes.searchName,
builder: (context, state) => const HeadlinesSearchPage(),
routes: [
// Sub-route for article details from search
GoRoute(
path: 'article/:id', // Relative path
name: Routes.searchArticleDetailsName, // New route name
builder: (context, state) {
final id = state.pathParameters['id']!;
return BlocProvider(
create:
(context) => HeadlineDetailsBloc(
headlinesRepository:
context.read<HtDataRepository<Headline>>(),
)..add(HeadlineDetailsRequested(headlineId: id)),
child: HeadlineDetailsPage(headlineId: id),
);
},
),
],
),
],
),
Expand Down
2 changes: 2 additions & 0 deletions lib/router/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ abstract final class Routes {
// --- Sub Routes ---
// Article details is now relative to feed
static const articleDetailsName = 'articleDetails';
// Add a new name for article details when accessed from search
static const searchArticleDetailsName = 'searchArticleDetails';
// Settings is now relative to account
static const settings = 'settings'; // Relative path
static const settingsName = 'settings';
Expand Down
Loading