Dart Uri parse fails on intent with data

Viewed 51

I am integrating with an external service that directs me to an intent to open an application. It returns some intents in a normal intent pattern and Uri.parse is able to correctly parse and return me the Uri which I can then start the intent.

intent:myappscheme://appcard?acctid=6570685061#Intent;package=com.example.appid;end;

void main() {
  try {
    final url = 'intent:myappscheme://appcard?acctid=6570685061#Intent;package=com.example.appid;end;';
    final uri = Uri.parse(url);
    print(uri);
  } catch (e) {
    print(e);
  }
}
intent:myappscheme://appcard?acctid=6570685061#Intent;package=com.example.appid;end;

The service also returns this pattern which the dart Uri.parse method rejects

intent://%7B"CD":"test","TK":"value"%7D/#Intent;package=com.example.appname;scheme=appname;end
import 'dart:ui';

void main() {
  try {
    final url = 'intent://%7B"CD":"test","TK":"value"%7D/#Intent;package=com.example.appname;scheme=appname;end';
    final uri = Uri.decodeFull(url);
    print(uri);
    final uri1 = Uri.parse(uri);
    print(uri1);
  } catch (e) {
    print(e);
  }
}

Testing with and without the decode I get the error:

intent://{"CD":"test","TK":"value"}/#Intent;package=com.example.appname;scheme=appname;end
FormatException: Invalid port (at character 16)
intent://{"CD":"test","TK":"value"}/#Intent;package=com.example.appname;sch...
               ^

Android is able to parse this type of intent correctly, but I would like to control this from the Flutter/Dart side:

Intent intent = Intent.parseUri(intentUrl, Intent.URI_INTENT_SCHEME)
Intent { 
  act=android.intent.action.VIEW 
  dat=appname://{"CD":"test","TK":"value"}/ 
  pkg=com.example.appname
}

Is there a similar method or way that I can use Uri.parse within Flutter/Dart to handle this style of Intent?

0 Answers
Related