Skip to content

Commit

Permalink
Second method to follow deep links with LaunchUrlHelper (#5450)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored Jun 28, 2024
1 parent 08a8df1 commit 32cab47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/smooth_app/lib/helpers/launch_url_helper.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import 'dart:io';

import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:url_launcher/url_launcher.dart';

class LaunchUrlHelper {
LaunchUrlHelper._();
const LaunchUrlHelper._();

static Future<void> launchURLAndFollowDeepLinks(
BuildContext context,
String url,
) async {
assert(url.isNotEmpty);

if (url.startsWith(RegExp('http(s)?://[a-z]*.openfoodfacts.(net|org)'))) {
AnalyticsHelper.trackOutlink(url: url);
GoRouter.of(context).go(url);
} else {
return launchURL(url);
}
}

/// Launches the url in an external browser.
static Future<void> launchURL(String url) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ class _TagLineContentButton extends StatelessWidget {
),
],
),
onPressed: () => LaunchUrlHelper.launchURL(link),
onPressed: () => LaunchUrlHelper.launchURLAndFollowDeepLinks(
context,
link,
),
);
}
}
Expand Down

0 comments on commit 32cab47

Please sign in to comment.