Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Works on iOS not on Android #3

Closed
sukhcha-in opened this issue May 22, 2022 · 2 comments
Closed

Works on iOS not on Android #3

sukhcha-in opened this issue May 22, 2022 · 2 comments

Comments

@sukhcha-in
Copy link

I'm getting this exception on Android specifically.

E/flutter (32405): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'SharedMedia' is not a subtype of type 'Map<Object?, Object?>' in type cast
E/flutter (32405): #0      SharedMedia.decode (package:share_handler_platform_interface/src/data/messages.dart:74)
E/flutter (32405): #1      ShareHandlerApi.getInitialSharedMedia (package:share_handler_platform_interface/src/data/messages.dart:155)
E/flutter (32405): <asynchronous suspension>
E/flutter (32405): #2      MethodChannelShareHandler.getInitialSharedMedia (package:share_handler_platform_interface/src/method_channel/method_channel_share_handler.dart:25)
E/flutter (32405): <asynchronous suspension>
E/flutter (32405): #3      IntentController.initPlatformState (package:app/global/controllers/intent_controller.dart:35)
E/flutter (32405): <asynchronous suspension>
E/flutter (32405):

Handler:

void initPlatformState() async {
    //deeplinks
    final appLinks = AppLinks();
    //shared links
    final sharedLinks = ShareHandlerPlatform.instance;

    //Cold Boot shared links
    SharedMedia? media = await sharedLinks.getInitialSharedMedia();
    if (media != null && media.content != null) {
      handler(media.content.toString());
    }

    //Cold Boot applinks
    final initialAppLink = await appLinks.getInitialAppLink();
    if (initialAppLink != null) {
      handler(initialAppLink.toString());
    }

    //Shared Links Listener
    sharedLinks.sharedMediaStream.listen((SharedMedia m) {
      handler(m.content.toString());
    });

    //Applinks Listener
    appLinks.uriLinkStream.listen((uri) {
      handler(uri.toString());
    });
  }
@sukhcha-in
Copy link
Author

It was having some conflicts with AppLinks package, so wrapped both initial links in try catch.

try {
      //Cold Boot shared links
      SharedMedia? media = await sharedLinks.getInitialSharedMedia();
      if (media != null && media.content != null) {
        print('Cold Boot shared links');
        handler(media.content.toString());
      }
    } catch (e) {
        log(e.toString());
    }

    try {
      //Cold Boot applinks
      final initialAppLink = await appLinks.getInitialAppLink();
      if (initialAppLink != null) {
        print('Cold Boot applinks');
        handler(initialAppLink.toString());
      }
    } catch (e) {
        log(e.toString());
    }

@daviddomkar
Copy link
Contributor

Hi. I encountered the same problem while using this package in an existing app but I am not using AppLinks. I think it is also a conflict with another package because it works just fine on a newly created app. Any idea how to debug this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants