Skip to content

Commit 331416e

Browse files
committed
fix: add error handling for launchUrl in Map screen
The OpenStreetMap attribution link in map_screen.dart called launchUrl() directly with no canLaunchUrl check and no error handling. If the URL fails to launch for any reason, the app throws an unhandled exception and crashes. Added canLaunchUrl check and logger.e() for the failure case, consistent with how the same issue is already handled in about_us_screen.dart, faq_screen.dart and connect_device_screen.dart. Fixes #3400
1 parent c8c50f5 commit 331416e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

lib/view/map_screen.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_map/flutter_map.dart';
33
import 'package:latlong2/latlong.dart';
44
import 'package:pslab/l10n/app_localizations.dart';
5+
import 'package:pslab/others/logger_service.dart';
56
import 'package:pslab/providers/locator.dart';
67
import 'package:pslab/theme/colors.dart';
78
import 'package:url_launcher/url_launcher.dart';
@@ -59,8 +60,17 @@ class MapScreen extends StatelessWidget {
5960
attributions: [
6061
TextSourceAttribution(
6162
appLocalizations.openStreetMapContributors,
62-
onTap: () => launchUrl(
63-
Uri.parse('https://openstreetmap.org/copyright')),
63+
onTap: () async {
64+
final uri =
65+
Uri.parse('https://openstreetmap.org/copyright');
66+
if (await canLaunchUrl(uri)) {
67+
await launchUrl(uri);
68+
} else {
69+
logger.e(
70+
'Could not launch https://openstreetmap.org/copyright',
71+
);
72+
}
73+
},
6474
),
6575
],
6676
),

0 commit comments

Comments
 (0)