-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlaunch_url_service.dart
74 lines (65 loc) · 2.52 KB
/
launch_url_service.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Flutter imports:
import 'package:flutter/material.dart';
// Package imports:
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart' as custom_tabs;
import 'package:url_launcher/url_launcher.dart' as url_launch;
// Project imports:
import 'package:notredame/core/managers/settings_manager.dart';
import 'package:notredame/locator.dart';
import 'package:notredame/ui/utils/app_theme.dart';
// Managers
// UTILS
// OTHER
class LaunchUrlService {
final SettingsManager settingsManager = locator<SettingsManager>();
Future<bool> canLaunch(String url) async {
final uri = Uri.parse(url);
return url_launch.canLaunchUrl(uri);
}
Future<bool> launch(String url) async {
final uri = Uri.parse(url);
return url_launch.launchUrl(uri);
}
Future<void> launchInBrowser(String url, Brightness brightness) async {
await custom_tabs.launch(
url,
customTabsOption: custom_tabs.CustomTabsOption(
toolbarColor: brightness == Brightness.light
? AppTheme.etsLightRed
: AppTheme.etsDarkRed,
enableDefaultShare: false,
enableUrlBarHiding: true,
showPageTitle: true,
animation: custom_tabs.CustomTabsSystemAnimation.slideIn(),
extraCustomTabs: const <String>[
// ref. https://play.google.com/store/apps/details?id=org.mozilla.firefox
'org.mozilla.firefox',
// https://play.google.com/store/apps/details?id=com.brave.browser
'com.brave.browser',
// https://play.google.com/store/apps/details?id=com.opera.browser
'com.opera.browser',
'com.opera.mini.native',
'com.opera.gx',
// https://play.google.com/store/apps/details?id=com.sec.android.app.sbrowser
'com.sec.android.app.sbrowser',
// ref. https://play.google.com/store/apps/details?id=com.microsoft.emmx
'com.microsoft.emmx',
// https://play.google.com/store/apps/details?id=com.UCMobile.intl
'com.UCMobile.intl',
],
),
safariVCOption: custom_tabs.SafariViewControllerOption(
preferredBarTintColor: brightness == Brightness.light
? AppTheme.etsLightRed
: AppTheme.etsDarkRed,
preferredControlTintColor: brightness == Brightness.light
? AppTheme.lightThemeBackground
: AppTheme.darkThemeBackground,
barCollapsingEnabled: true,
entersReaderIfAvailable: false,
dismissButtonStyle:
custom_tabs.SafariViewControllerDismissButtonStyle.close,
),
);
}
}