ShekarMudaliyar / social_share

Flutter package to share images/videos/text on social media
https://pub.dev/packages/social_share
MIT License
112 stars 191 forks source link

shareTwitter without URL results in error #55

Open GoldenSoju opened 3 years ago

GoldenSoju commented 3 years ago

Seems like a null-safety error. I think in social_share.dart you would have to change the code:

if (Platform.isAndroid) {
      modifiedUrl = Uri.parse(url!).toString().replaceAll('#', "%23");
    } else {
      modifiedUrl = Uri.parse(url!).toString();
    }

to

if (Platform.isAndroid) {
      modifiedUrl = Uri.parse(url?).toString().replaceAll('#', "%23");
    } else {
      modifiedUrl = Uri.parse(url?).toString();
    }

Otherwise you promise (= !) a URL that might not be given. So better replace the exclamation mark with question mark or check if URL is not null before running the parse part.

Bharathh-Raj commented 3 years ago

It is better to use tryParse this way if (Platform.isAndroid) { modifiedUrl = Uri.tryParse(url)?.toString()?.replaceAll('#', "%23"); } else { modifiedUrl = Uri.tryParse(url)?.toString(); } or just use null check beforehand