From 01adf863d06a179332136a3fd80210a38b146265 Mon Sep 17 00:00:00 2001 From: OmarHatem28 Date: Tue, 9 Aug 2022 13:34:40 +0200 Subject: [PATCH] Add the ability to launch app from Crypto QR codes --- android/app/src/main/AndroidManifestBase.xml | 9 +++++ lib/main.dart | 37 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/android/app/src/main/AndroidManifestBase.xml b/android/app/src/main/AndroidManifestBase.xml index f43b0369b..f4023f532 100644 --- a/android/app/src/main/AndroidManifestBase.xml +++ b/android/app/src/main/AndroidManifestBase.xml @@ -38,6 +38,15 @@ android:scheme="cakewallet" android:host="y.at" /> + + + + + + + + + with SingleTickerProviderStateMixin { super.initState(); //_handleIncomingLinks(); //_handleInitialUri(); + + initUniLinks(); } @override @@ -210,6 +212,41 @@ class AppState extends State with SingleTickerProviderStateMixin { super.dispose(); } + /// handle app links while the app is already started - be it in + /// the foreground or in the background. + Future initUniLinks() async { + try { + stream = getLinksStream().listen((String link) { + handleDeepLinking(link); + }); + + final String initialLink = await getInitialLink(); + + handleDeepLinking(initialLink); + } catch (e) { + print(e); + } + } + + void handleDeepLinking(String link) async { + if (link == null || !mounted) return; + + final List urlComponents = link.split(":"); + + switch (urlComponents.first) { + case "bitcoin": + print("@@@@@@@@@@@@@@@@@@@@@@@@@@"); + print("Bitcoin QR Code: \n${link}"); + break; + case "litecoin": + case "haven": + case "monero": + default: + print("@@@@@@@@@@@@@@@@@@@@@@@@@@"); + print(link); + } + } + Future _handleInitialUri() async { try { final uri = await getInitialUri();