Skip to content

Commit 3dc15ed

Browse files
committed
refactor(status): improve error handling for update URLs
- Add snackbar notification when iOS or Android update URL cannot be opened - Change launch mode to external application for both URLs - Check if context is mounted before showing snackbar
1 parent fe345e1 commit 3dc15ed

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

lib/status/view/update_required_page.dart

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,20 @@ class UpdateRequiredPage extends StatelessWidget {
6464
child: ElevatedButton.icon(
6565
onPressed: () async {
6666
final url = Uri.parse(iosUpdateUrl);
67-
if (await canLaunchUrl(url)) {
68-
await launchUrl(url);
67+
if (!await launchUrl(
68+
url,
69+
mode: LaunchMode.externalApplication,
70+
)) {
71+
if (!context.mounted) return;
72+
ScaffoldMessenger.of(context)
73+
..hideCurrentSnackBar()
74+
..showSnackBar(
75+
SnackBar(
76+
content: Text(
77+
l10n.couldNotOpenUpdateUrl(iosUpdateUrl),
78+
),
79+
),
80+
);
6981
}
7082
},
7183
icon: const Icon(Icons.apple),
@@ -79,8 +91,20 @@ class UpdateRequiredPage extends StatelessWidget {
7991
child: ElevatedButton.icon(
8092
onPressed: () async {
8193
final url = Uri.parse(androidUpdateUrl);
82-
if (await canLaunchUrl(url)) {
83-
await launchUrl(url);
94+
if (!await launchUrl(
95+
url,
96+
mode: LaunchMode.externalApplication,
97+
)) {
98+
if (!context.mounted) return;
99+
ScaffoldMessenger.of(context)
100+
..hideCurrentSnackBar()
101+
..showSnackBar(
102+
SnackBar(
103+
content: Text(
104+
l10n.couldNotOpenUpdateUrl(androidUpdateUrl),
105+
),
106+
),
107+
);
84108
}
85109
},
86110
icon: const Icon(Icons.shop),

0 commit comments

Comments
 (0)