Skip to content
Merged
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
28 changes: 13 additions & 15 deletions lib/screens/nearby_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ class NearbyScreen extends StatefulWidget {
}

class _NearbyStopGroup {
const _NearbyStopGroup({
required this.stopName,
required this.distanceMeters,
required this.routes,
});
const _NearbyStopGroup({required this.stopName, required this.routes});

final String stopName;
final double distanceMeters;
final List<NearbyRouteRow> routes;
}

Expand Down Expand Up @@ -337,14 +332,12 @@ class _NearbyScreenState extends State<NearbyScreen> {
/// available.
List<_NearbyStopGroup> _buildGroups(String locale) {
final groupOrder = <String>[];
final groupDistances = <String, double>{};
final groupRoutes = <String, List<NearbyStopResult>>{};

for (final item in _results) {
final name = item.stop.stopName;
if (!groupRoutes.containsKey(name)) {
groupOrder.add(name);
groupDistances[name] = item.distanceMeters;
groupRoutes[name] = [];
}
groupRoutes[name]!.add(item);
Expand All @@ -354,7 +347,6 @@ class _NearbyScreenState extends State<NearbyScreen> {
for (final name in groupOrder)
_NearbyStopGroup(
stopName: name,
distanceMeters: groupDistances[name]!,
// Sort first: the labeller only appends a direction ordinal when two
// rows would otherwise read alike, so it has to see the final order.
routes: labelNearbyRouteDirections(
Expand Down Expand Up @@ -429,6 +421,13 @@ class _NearbyScreenState extends State<NearbyScreen> {
],
),
),
const SizedBox(width: 8),
Chip(
avatar: const Icon(Icons.directions_walk_rounded, size: 16),
label: Text(formatDistance(item.distanceMeters)),
visualDensity: VisualDensity.compact,
padding: EdgeInsets.zero,
),
Icon(
Icons.chevron_right_rounded,
size: 20,
Expand Down Expand Up @@ -580,12 +579,11 @@ class _NearbyScreenState extends State<NearbyScreen> {
16,
),
),
child: Text(
formatDistance(
group.distanceMeters,
),
textAlign: TextAlign.center,
style: theme.textTheme.labelMedium,
child: Icon(
Icons.directions_bus_rounded,
color: theme
.colorScheme
.onPrimaryContainer,
),
),
const SizedBox(width: 14),
Expand Down
3 changes: 3 additions & 0 deletions test/nearby_direction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ void main() {
expect(find.text('台北市'), findsNWidgets(2));
expect(find.text('往撫遠街'), findsOneWidget);
expect(find.text('往捷運松山站'), findsOneWidget);
// Same-name stops on opposite sides keep their own walking distance.
expect(find.text('20m'), findsOneWidget);
expect(find.text('30m'), findsOneWidget);
} finally {
await tester.pumpWidget(const SizedBox.shrink());
debugDefaultTargetPlatformOverride = null;
Expand Down
Loading