-
Notifications
You must be signed in to change notification settings - Fork 12
/
web_link_card_viewmodel.dart
43 lines (35 loc) · 1.51 KB
/
web_link_card_viewmodel.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
// Flutter imports:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// Package imports:
import 'package:stacked/stacked.dart';
// Project imports:
import 'package:notredame/core/constants/router_paths.dart';
import 'package:notredame/core/models/quick_link.dart';
import 'package:notredame/core/services/analytics_service.dart';
import 'package:notredame/core/services/launch_url_service.dart';
import 'package:notredame/core/services/navigation_service.dart';
import 'package:notredame/locator.dart';
class WebLinkCardViewModel extends BaseViewModel {
/// used to redirect on the security.
final NavigationService _navigationService = locator<NavigationService>();
final AnalyticsService _analyticsService = locator<AnalyticsService>();
final LaunchUrlService _launchUrlService = locator<LaunchUrlService>();
/// used to open a website or the security view
Future<void> onLinkClicked(QuickLink link, Brightness brightness) async {
_analyticsService.logEvent("QuickLink", "QuickLink clicked: ${link.name}");
if (link.link == 'security') {
_navigationService.pushNamed(RouterPaths.security);
} else {
try {
await _launchUrlService.launchInBrowser(link.link, brightness);
} catch (error) {
// An exception is thrown if browser app is not installed on Android device.
await launchWebView(link);
}
}
}
Future<void> launchWebView(QuickLink link) async {
_navigationService.pushNamed(RouterPaths.webView, arguments: link);
}
}