@@ -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: [
0 commit comments