Line data Source code
1 : // Copyright 2026 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'dart:async';
5 :
6 : import 'package:app_finance/_classes/controller/deep_link/url_scheme.dart';
7 : import 'package:app_links/app_links.dart';
8 : import 'package:flutter/foundation.dart';
9 :
10 : // Links opening the application
11 : // > fingrom://integration/enablebanking?... sent back by the bank's authorization
12 : class DeepLinkHandler {
13 : static const scheme = 'fingrom';
14 : static const enableBankingPath = '/enablebanking';
15 :
16 3 : static final enableBankingCallback = ValueNotifier<Uri?>(null);
17 : static StreamSubscription<Uri>? _subscription;
18 :
19 1 : static Future<void> init({Stream<Uri>? links}) async {
20 3 : unawaited(registerUrlScheme(scheme).catchError((_) {}));
21 0 : await _subscription?.cancel();
22 : try {
23 1 : _subscription = (links ?? AppLinks().uriLinkStream).listen(handle, onError: (_) {});
24 : } catch (_) {
25 : // Platform without link support
26 : }
27 : }
28 :
29 1 : static bool isEnableBankingCallback(Uri uri) =>
30 6 : uri.scheme == scheme && uri.host == 'integration' && uri.path == enableBankingPath;
31 :
32 1 : static bool handle(Uri uri) {
33 1 : if (!isEnableBankingCallback(uri)) {
34 : return false;
35 : }
36 2 : enableBankingCallback.value = uri;
37 : return true;
38 : }
39 :
40 1 : static Uri? takeEnableBankingCallback() {
41 2 : final value = enableBankingCallback.value;
42 2 : enableBankingCallback.value = null;
43 : return value;
44 : }
45 : }
|