Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: launch url with toast #1186

Merged
merged 3 commits into from
Mar 5, 2024
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
10 changes: 8 additions & 2 deletions uni/lib/controller/networking/url_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import 'package:url_launcher/url_launcher.dart';

Future<void> launchUrlWithToast(BuildContext context, String url) async {
final validUrl = Uri.parse(url);
if (url != '' && canLaunchUrl(validUrl) as bool) {
await launchUrl(Uri.parse(url));
final canLaunch = url != '' && await canLaunchUrl(validUrl);

if (!context.mounted) {
return;
}

if (canLaunch) {
await launchUrl(validUrl);
} else {
await ToastMessage.error(
context,
Expand Down
7 changes: 4 additions & 3 deletions uni/lib/view/locations/widgets/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:latlong2/latlong.dart';
import 'package:uni/controller/networking/url_launcher.dart';
import 'package:uni/model/entities/location_group.dart';
import 'package:uni/view/locations/widgets/floorless_marker_popup.dart';
import 'package:uni/view/locations/widgets/marker.dart';
import 'package:uni/view/locations/widgets/marker_popup.dart';
import 'package:url_launcher/url_launcher.dart';

class LocationsMap extends StatelessWidget {
LocationsMap({
Expand Down Expand Up @@ -62,8 +62,9 @@ class LocationsMap extends StatelessWidget {
child: ColoredBox(
color: Theme.of(context).colorScheme.onPrimary.withOpacity(0.8),
child: GestureDetector(
onTap: () => launchUrl(
Uri(host: 'openstreetmap.org', path: '/copyright'),
onTap: () => launchUrlWithToast(
context,
'https://www.openstreetmap.org/copyright',
),
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 8),
Expand Down
12 changes: 4 additions & 8 deletions uni/lib/view/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_svg/svg.dart';
import 'package:logger/logger.dart';
import 'package:provider/provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/controller/networking/url_launcher.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/model/entities/login_exceptions.dart';
import 'package:uni/model/providers/startup/session_provider.dart';
Expand All @@ -14,7 +15,6 @@ import 'package:uni/view/common_widgets/toast_message.dart';
import 'package:uni/view/home/widgets/exit_app_dialog.dart';
import 'package:uni/view/login/widgets/inputs.dart';
import 'package:uni/view/theme.dart';
import 'package:url_launcher/url_launcher.dart';

class LoginPageView extends StatefulWidget {
const LoginPageView({super.key});
Expand Down Expand Up @@ -248,7 +248,7 @@ class LoginPageViewState extends State<LoginPageView> {
),
),
),
onTap: () => launchUrl(Uri.parse('https://self-id.up.pt/reset')),
onTap: () => launchUrlWithToast(context, 'https://self-id.up.pt/reset'),
);
}

Expand Down Expand Up @@ -301,12 +301,8 @@ class LoginPageViewState extends State<LoginPageView> {
),
ElevatedButton(
child: Text(S.of(context).change),
onPressed: () async {
const url = 'https://self-id.up.pt/password';
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));
}
},
onPressed: () =>
launchUrlWithToast(context, 'https://self-id.up.pt/password'),
),
],
);
Expand Down
Loading