avioli / uni_links

Flutter plugin for accepting incoming links.
BSD 2-Clause "Simplified" License
563 stars 303 forks source link

App Link or Deep Link doesn't work when click url in kakaotalk chat #99

Closed yoseptara closed 3 years ago

yoseptara commented 3 years ago

I'm using [https scheme] and am testing on my [Poco M3, Mi 9T], which is running [Android 10].

Nothing happen when I click the url and it just open the webview (kakaotalk) But It worked in many other social media (line, instagram, whatsapp, telegram, etc)

My code :

import 'dart:async';

import 'package:chaca_market/asking_update_page.dart';
import 'package:chaca_market/const.dart';
import 'package:chaca_market/pages/create_profile/create_profile.dart';
import 'package:chaca_market/pages/get_started/get_started_page.dart';
import 'package:chaca_market/pages/main_menu/main_menu_page.dart';
import 'package:chaca_market/pages/products/product_detail/product_detail.dart';
import 'package:chaca_market/pages/profile/profile_seller_page.dart';
import 'package:chaca_market/services/auth_service.dart';
import 'package:chaca_market/services/notification_service.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:new_version/new_version.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uni_links/uni_links.dart';

class PermissionPage extends StatefulWidget {
  static const route = '/permision_page';
  @override
  _PermissionPageState createState() => _PermissionPageState();
}

class _PermissionPageState extends State<PermissionPage> {
  String _latestLink = 'Unknown';
  StreamSubscription _sub;
  AuthService authService = AuthService();
  NotificationService _notificationService = NotificationService();

  notificationsServiceGetCalled() async {
    await _notificationService.registerNotification(await authService.getCurrentUserUid());
    _notificationService.configLocalNotification();
  }

  Future<bool> checkingNewVersion() async {
    final newVersion = NewVersion(
      context: context,
    );
    final status = await newVersion.getVersionStatus();

    return status.canUpdate;
  }

  initPlatformStateForStringUniLinks() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    // Attach a listener to the links stream

    _sub = getLinksStream().listen((String link) {
      if (!mounted) return;
      setState(() {
        _latestLink = link ?? 'Unknown';

        try {} on FormatException {}
      });
    }, onError: (err) {
      if (!mounted) return;
      setState(() {
        _latestLink = 'Failed to get latest link: $err.';
      });
    });

    // Attach a second listener to the stream
    getLinksStream().listen((String link) {
      // print('got link: $link');
    }, onError: (err) {
      // print('got err: $err');
    });

    // Get the latest link
    String initialLink;
    // Uri initialUri;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      initialLink = await getInitialLink();
      // print('initial link: $initialLink');
    } on PlatformException {
      initialLink = 'Failed to get initial link.';
    } on FormatException {
      initialLink = 'Failed to parse the initial link as Uri.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _latestLink = initialLink;
    });

    if (_latestLink == null) {
      if (prefs.getString(kPrefsAccessTokenKey) == null) {
        Get.offAll(GetStartedPage());
      } else {
        await authService?.getUserId() == null
            ? Get.offAll(CreateProfilePage(
                phoneNumber: prefs.getString(kPrefsPhoneNumberKey),
                countryISOCode: prefs.getString(kPrefsCountryISOCodeKey),
                iso: prefs.getString(kPrefsIsoKey),
              ))
            : Get.offAll(MainMenuPage());
      }
    } else {
      if (_latestLink.contains('product')) {
        final QuerySnapshot result =
            await FirebaseFirestore.instance.collection('shortenUrl').where('shortenUrl', isEqualTo: _latestLink).get();
        final List<DocumentSnapshot> documents = result.docs;
        if (documents.length == 0) {
          if (prefs.getString(kPrefsAccessTokenKey) == null) {
            Get.offAll(GetStartedPage());
          } else {
            await authService.getUserId() == null
                ? Get.offAll(CreateProfilePage(
                    phoneNumber: prefs.getString(kPrefsPhoneNumberKey),
                    countryISOCode: prefs.getString(kPrefsCountryISOCodeKey),
                    iso: prefs.getString(kPrefsIsoKey),
                  ))
                : Get.offAll(MainMenuPage());
          }
        } else {
          if (prefs.getString(kPrefsAccessTokenKey) == null) {
            Get.offAll(GetStartedPage());
          } else {
            Get.offAll(ProductDetailForBuyerPage(
              productID: documents[0].data()['product_id'],
              backToMainMenuPage: true,
            ));
          }
        }
      } else if (_latestLink.contains('profiles')) {
        final QuerySnapshot result = await FirebaseFirestore.instance
            .collection('shortenProfileUrl')
            .where('shortenUrl', isEqualTo: _latestLink)
            .get();
        final List<DocumentSnapshot> documents = result.docs;
        if (documents.length == 0) {
          if (prefs.getString(kPrefsAccessTokenKey) == null) {
            Get.offAll(GetStartedPage());
          } else {
            await authService.getUserId() == null
                ? Get.offAll(CreateProfilePage(
                    phoneNumber: prefs.getString(kPrefsPhoneNumberKey),
                    countryISOCode: prefs.getString(kPrefsCountryISOCodeKey),
                    iso: prefs.getString(kPrefsIsoKey),
                  ))
                : Get.offAll(MainMenuPage());
          }
        } else {
          if (prefs.getString(kPrefsAccessTokenKey) == null) {
            Get.offAll(GetStartedPage());
          } else {
            Get.offAll(ProfileSellerPage(
              profileId: documents[0].data()['user_id'],
              backToMainMenuPage: true,
            ));
          }
        }
      } else {
        if (prefs.getString(kPrefsAccessTokenKey) == null) {
          Get.offAll(GetStartedPage());
        } else {
          await authService.getUserId() == null
              ? Get.offAll(CreateProfilePage(
                  phoneNumber: prefs.getString(kPrefsPhoneNumberKey),
                  countryISOCode: prefs.getString(kPrefsCountryISOCodeKey),
                  iso: prefs.getString(kPrefsIsoKey),
                ))
              : Get.offAll(MainMenuPage());
        }
      }
    }
    notificationsServiceGetCalled();
  }

  initPlatformState() async {
    bool choose = await checkingNewVersion();
    if (choose) {
      Navigator.pushAndRemoveUntil(
          context,
          PageRouteBuilder(
            pageBuilder: (context, animation1, animation2) => AskingUpdatePage(),
            transitionDuration: Duration(seconds: 0),
          ),
          (Route<dynamic> route) => false);
    } else {
      await initPlatformStateForStringUniLinks();
    }
  }

  @override
  dispose() {
    if (_sub != null) _sub.cancel();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();

    initPlatformState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold();
  }
}

Flutter Doctor :

[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.18363.1379], locale en-US)
    • Flutter version 1.22.6 at C:\flutter
    • Framework revision 9b2d32b605 (5 weeks ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\TARA\AppData\Local\Android\Sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = C:\Users\TARA\AppData\Local\Android\Sdk
    • Java binary at: D:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    • Android Studio at D:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality. (this issue occurs in flutter stable channel but it can be ignored)
    X Dart plugin not installed; this adds Dart specific functionality.  (this issue occurs in flutter stable channel but it can be ignored)
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.52.1)
    • VS Code at C:\Users\TARA\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.19.0

Android Manifest :

<activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:showWhenLocked="true"
            android:turnScreenOn="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="https"
                    android:host="ly.chaca.io" />
            </intent-filter>
avioli commented 3 years ago

Did you figure it out?

yoseptara commented 3 years ago

Did you figure it out?

Nopee, I just skip this issue because kakaotalk is rarely used in my country

IsmaelDeveloper commented 2 years ago

i have the exact same problem. Is there any issue about it ?