From 287a6a28c852dd60ad384ff804fb6970865f2538 Mon Sep 17 00:00:00 2001 From: livinglist Date: Mon, 20 Jan 2025 20:37:02 -0800 Subject: [PATCH 1/2] fix: item screen deeplink. --- lib/config/custom_router.dart | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/config/custom_router.dart b/lib/config/custom_router.dart index 32c3b879..d413b197 100644 --- a/lib/config/custom_router.dart +++ b/lib/config/custom_router.dart @@ -3,7 +3,11 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:hacki/config/locator.dart'; import 'package:hacki/cubits/cubits.dart'; +import 'package:hacki/extensions/extensions.dart'; +import 'package:hacki/models/item/item.dart'; +import 'package:hacki/repositories/hacker_news_repository.dart'; import 'package:hacki/screens/screens.dart'; +import 'package:hacki/styles/dimens.dart'; final GoRouter router = GoRouter( observers: [ @@ -25,6 +29,32 @@ final GoRouter router = GoRouter( return ItemScreen.phone(args); }, ), + GoRoute( + path: '${ItemScreen.routeName}/:itemId', + builder: (BuildContext context, GoRouterState state) { + final String? itemIdStr = state.pathParameters['itemId']; + final int? itemId = itemIdStr?.itemId; + if (itemId == null) { + throw GoError("item id can't be null"); + } + return FutureBuilder( + future: locator.get().fetchItem(id: itemId), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + final ItemScreenArgs args = + ItemScreenArgs(item: snapshot.data!); + return ItemScreen.phone(args); + } else { + return const Center( + child: CircularProgressIndicator( + strokeWidth: Dimens.pt2, + ), + ); + } + }, + ); + }, + ), GoRoute( path: LogScreen.routeName, builder: (_, __) => const LogScreen(), From 92a415051ba51cd4d088e65b2ba53e9d56a049ff Mon Sep 17 00:00:00 2001 From: livinglist Date: Mon, 20 Jan 2025 21:50:24 -0800 Subject: [PATCH 2/2] fix route. --- ios/StoryWidget/StoryWidget.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/StoryWidget/StoryWidget.swift b/ios/StoryWidget/StoryWidget.swift index 4c65720b..53ea44fd 100644 --- a/ios/StoryWidget/StoryWidget.swift +++ b/ios/StoryWidget/StoryWidget.swift @@ -23,7 +23,7 @@ struct StoryWidgetView : View { .containerBackground(for: .widget) { Color(UIColor.secondarySystemBackground) } - .widgetURL(URL(string: "\(story.id)")) + .widgetURL(URL(string: "/item/\(story.id)")) default: HStack { VStack { @@ -62,7 +62,7 @@ struct StoryWidgetView : View { .containerBackground(for: .widget) { Color(UIColor.secondarySystemBackground) } - .widgetURL(URL(string: "\(story.id)")) + .widgetURL(URL(string: "/item/\(story.id)")) } } }