Skip to content
Open
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
47 changes: 47 additions & 0 deletions lib/core/app_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,53 @@ 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<List<StopRouteSearchResult>> searchRoutesByStopAcrossAllProviders(
String query, {
required BusProvider current,
}) async {
if (kIsWeb) return searchRoutesByStopFromApi(query);
final results = <StopRouteSearchResult>[
...await repository.searchRoutesByStopName(query, provider: current),
];
final remoteProviders = <BusProvider>[];
for (final provider in BusProvider.values) {
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)) {
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<List<StopRouteSearchResult>> searchRoutesByStopFromApi(
String query, {
Iterable<BusProvider>? providers,
Expand Down
12 changes: 9 additions & 3 deletions lib/screens/route_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4620,7 +4620,13 @@ class _RouteDetailScreenState extends State<RouteDetailScreen>
}

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
Expand Down Expand Up @@ -4678,9 +4684,9 @@ class _RouteDetailScreenState extends State<RouteDetailScreen>
Object? localError;
StackTrace? localStackTrace;
try {
final results = await controller.searchRoutesByStop(
final results = await controller.searchRoutesByStopAcrossAllProviders(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Medium: Repository stop-search normalization folds 臺 to 台, but _normalizeStopRouteLookupName only lowercases and removes whitespace. A sibling result named 台北車站 can be returned for a current stop named 臺北車站, then discarded by this equality filter. Reuse the repository’s stop-name normalization contract here.

stop.stopName,
provider: widget.provider,
current: widget.provider,
);
local = results
.where(
Expand Down
Loading