Skip to content

Commit a2ce738

Browse files
committed
refactor(router): consolidate entity details routes into a single route
- Replace separate routes for topic, source, and country details with a generic entity-details route - Update route path to use parameters for entity type and ID - Modify route builder to handle different entity types dynamically - Update Routes class to reflect the new consolidated route
1 parent 88ffa85 commit a2ce738

File tree

2 files changed

+22
-94
lines changed

2 files changed

+22
-94
lines changed

lib/router/router.dart

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -263,101 +263,33 @@ GoRouter createRouter({
263263
),
264264
],
265265
),
266-
// --- Entity Details Routes (Top Level) ---
266+
// --- Entity Details Route (Top Level) ---
267+
// This route handles displaying details for various content entities
268+
// (Topic, Source, Country) based on path parameters.
267269
GoRoute(
268-
path: Routes.topicDetails,
269-
name: Routes.topicDetailsName,
270+
path: Routes.entityDetails,
271+
name: Routes.entityDetailsName,
270272
builder: (context, state) {
271-
final args = state.extra as EntityDetailsPageArguments?;
272-
if (args == null) {
273+
final entityTypeString = state.pathParameters['type'];
274+
final entityId = state.pathParameters['id'];
275+
276+
if (entityTypeString == null || entityId == null) {
273277
return const Scaffold(
274-
body: Center(
275-
child: Text('Error: Missing topic details arguments'),
276-
),
278+
body: Center(child: Text('entity Details Missing Arguments')),
277279
);
278280
}
279-
final adThemeStyle = AdThemeStyle.fromTheme(Theme.of(context));
280-
return MultiBlocProvider(
281-
providers: [
282-
BlocProvider.value(value: accountBloc),
283-
BlocProvider(
284-
create: (context) =>
285-
EntityDetailsBloc(
286-
headlinesRepository: context
287-
.read<DataRepository<Headline>>(),
288-
topicRepository: context.read<DataRepository<Topic>>(),
289-
sourceRepository: context.read<DataRepository<Source>>(),
290-
countryRepository: context
291-
.read<DataRepository<Country>>(),
292-
accountBloc: accountBloc,
293-
appBloc: context.read<AppBloc>(),
294-
feedDecoratorService: feedDecoratorService,
295-
)..add(
296-
EntityDetailsLoadRequested(
297-
entityId: args.entityId,
298-
contentType: args.contentType,
299-
adThemeStyle: adThemeStyle,
300-
),
301-
),
302-
),
303-
],
304-
child: EntityDetailsPage(args: args),
281+
282+
final contentType = ContentType.values.firstWhere(
283+
(e) => e.name == entityTypeString,
284+
orElse: () =>
285+
throw FormatException('Unknown ContentType: $entityTypeString'),
305286
);
306-
},
307-
),
308-
GoRoute(
309-
path: Routes.sourceDetails,
310-
name: Routes.sourceDetailsName,
311-
builder: (context, state) {
312-
final args = state.extra as EntityDetailsPageArguments?;
313-
if (args == null) {
314-
return const Scaffold(
315-
body: Center(
316-
child: Text('Error: Missing source details arguments'),
317-
),
318-
);
319-
}
320-
final adThemeStyle = AdThemeStyle.fromTheme(Theme.of(context));
321-
return MultiBlocProvider(
322-
providers: [
323-
BlocProvider.value(value: accountBloc),
324-
BlocProvider(
325-
create: (context) =>
326-
EntityDetailsBloc(
327-
headlinesRepository: context
328-
.read<DataRepository<Headline>>(),
329-
topicRepository: context.read<DataRepository<Topic>>(),
330-
sourceRepository: context.read<DataRepository<Source>>(),
331-
countryRepository: context
332-
.read<DataRepository<Country>>(),
333-
accountBloc: accountBloc,
334-
appBloc: context.read<AppBloc>(),
335-
feedDecoratorService: feedDecoratorService,
336-
)..add(
337-
EntityDetailsLoadRequested(
338-
entityId: args.entityId,
339-
contentType: args.contentType,
340-
adThemeStyle: adThemeStyle,
341-
),
342-
),
343-
),
344-
],
345-
child: EntityDetailsPage(args: args),
287+
288+
final args = EntityDetailsPageArguments(
289+
entityId: entityId,
290+
contentType: contentType,
346291
);
347-
},
348-
),
349-
GoRoute(
350-
path: Routes.countryDetails,
351-
name: Routes.countryDetailsName,
352-
builder: (context, state) {
353-
final args = state.extra as EntityDetailsPageArguments?;
354-
if (args == null) {
355-
return const Scaffold(
356-
body: Center(
357-
child: Text('Error: Missing country details arguments'),
358-
),
359-
);
360-
}
292+
361293
final adThemeStyle = AdThemeStyle.fromTheme(Theme.of(context));
362294
return MultiBlocProvider(
363295
providers: [

lib/router/routes.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ abstract final class Routes {
3838
static const notificationsName = 'notifications';
3939

4040
// --- Entity Details Routes (can be accessed from multiple places) ---
41-
static const topicDetails = '/topic-details';
42-
static const topicDetailsName = 'topicDetails';
43-
static const sourceDetails = '/source-details';
44-
static const sourceDetailsName = 'sourceDetails';
45-
static const countryDetails = '/country-details';
46-
static const countryDetailsName = 'countryDetails';
41+
static const entityDetails = '/entity-details/:type/:id';
42+
static const entityDetailsName = 'entityDetails';
4743

4844
// --- Authentication Routes ---
4945
static const authentication = '/authentication';

0 commit comments

Comments
 (0)