From a7dd407167e0fcc645924367b68eb8c13355194d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=84=A7=E4=B8=9E=E5=8B=9B?= <142199173+steventeng2022@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:53:13 +0800 Subject: [PATCH 1/2] fix: list stop routes managed by other cities (#113) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 站牌經過路線 sheet only searched the current route's city, so routes from other cities serving the same stop were missing. Search all cities (local DB where ready, API otherwise) and merge as before. Co-Authored-By: Claude Sonnet 5.5 --- lib/core/app_controller.dart | 42 ++++++++++++++++++++++++++++ lib/screens/route_detail_screen.dart | 4 +-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/core/app_controller.dart b/lib/core/app_controller.dart index 9a811c16..5c052495 100644 --- a/lib/core/app_controller.dart +++ b/lib/core/app_controller.dart @@ -2628,6 +2628,48 @@ class AppController extends ChangeNotifier { return results; } + /// Finds every route that serves a stop name regardless of which city + /// manages the route. Cities whose local database is ready are searched + /// locally; the rest (and the whole lookup on web) go through the API, so a + /// route from a neighbouring city is listed even when that city's data was + /// never downloaded. The [current] provider is searched first and its errors + /// propagate; failures for other cities are skipped. + Future> searchRoutesByStopAcrossAllProviders( + String query, { + required BusProvider current, + }) async { + if (kIsWeb) return searchRoutesByStopFromApi(query); + final results = [ + ...await repository.searchRoutesByStopName(query, provider: current), + ]; + final remoteProviders = []; + for (final provider in BusProvider.values) { + if (provider == current || !provider.supportsLocalDatabase) continue; + try { + await ensureProviderDatabaseState(provider); + if (!isDatabaseReady(provider)) { + remoteProviders.add(provider); + continue; + } + results.addAll( + await repository.searchRoutesByStopName(query, provider: provider), + ); + } catch (error) { + debugPrint('Stop route lookup skipped for ${provider.name}: $error'); + } + } + if (remoteProviders.isNotEmpty) { + try { + results.addAll( + await searchRoutesByStopFromApi(query, providers: remoteProviders), + ); + } catch (error) { + debugPrint('Stop route API lookup error: $error'); + } + } + return results; + } + Future> searchRoutesByStopFromApi( String query, { Iterable? providers, diff --git a/lib/screens/route_detail_screen.dart b/lib/screens/route_detail_screen.dart index f2600b8a..c38466f8 100644 --- a/lib/screens/route_detail_screen.dart +++ b/lib/screens/route_detail_screen.dart @@ -4678,9 +4678,9 @@ class _RouteDetailScreenState extends State Object? localError; StackTrace? localStackTrace; try { - final results = await controller.searchRoutesByStop( + final results = await controller.searchRoutesByStopAcrossAllProviders( stop.stopName, - provider: widget.provider, + current: widget.provider, ); local = results .where( From f3967f5be35c66e20d1d963b46cf41d026355dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=84=A7=E4=B8=9E=E5=8B=9B?= <142199173+steventeng2022@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:04:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20include=20intercity=20and=20fold=20?= =?UTF-8?q?=E8=87=BA/=E5=8F=B0=20in=20cross-city=20stop=20routes=20lookup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- lib/core/app_controller.dart | 7 ++++++- lib/screens/route_detail_screen.dart | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/core/app_controller.dart b/lib/core/app_controller.dart index 5c052495..f25ddc1f 100644 --- a/lib/core/app_controller.dart +++ b/lib/core/app_controller.dart @@ -2644,7 +2644,12 @@ class AppController extends ChangeNotifier { ]; final remoteProviders = []; for (final provider in BusProvider.values) { - if (provider == current || !provider.supportsLocalDatabase) continue; + if (provider == current) continue; + if (!provider.supportsLocalDatabase) { + // Intercity has no local database; it is only reachable via the API. + remoteProviders.add(provider); + continue; + } try { await ensureProviderDatabaseState(provider); if (!isDatabaseReady(provider)) { diff --git a/lib/screens/route_detail_screen.dart b/lib/screens/route_detail_screen.dart index c38466f8..a7096481 100644 --- a/lib/screens/route_detail_screen.dart +++ b/lib/screens/route_detail_screen.dart @@ -4620,7 +4620,13 @@ class _RouteDetailScreenState extends State } String _normalizeStopRouteLookupName(String value) { - return value.trim().toLowerCase().replaceAll(RegExp(r'\s+'), ''); + // Same 臺→台 folding as the repository's stop search, otherwise a sibling + // result spelled 台北車站 is dropped for a stop named 臺北車站. + return value + .trim() + .toLowerCase() + .replaceAll('臺', '台') + .replaceAll(RegExp(r'\s+'), ''); } // Keys ([stopRouteMergeKey]) of the entries in the related-stop-routes sheet