Search code examples
flutterfacebookpostshare

How to share Text post to Facebook directly in Flutter


Simple how can direkly open Facebook app to share text and link. without open popup

I have test many plugin but all not work like what I need.

enter image description here

without this popup need to share direkly to Facebook.

this what I test but not work as expect

var url = 'facebook.com/sharer/sharer.php';
    final Uri launchUri = Uri(
      scheme: 'https',
      path: url,
      query: encodeQueryParameters(<String, String>{
        'text': 'test text - ' + postImagelink.toString(),
      }),
    );

or like

 String fbProtocolUrl;
    if (Platform.isIOS) {
      fbProtocolUrl = 'fb://';
    } else {
      fbProtocolUrl = 'fb://';
    }

    String fallbackUrl = 'https://www.facebook.com/stories/create';

    try {
      Uri fbBundleUri = Uri.parse(fbProtocolUrl);
      fbBundleUri.query!=encodeQueryParameters(<String, String>{
        'text': 'test text - ' + _postImagelink.toString(),
      });
      var canLaunchNatively = await canLaunchUrl(fbBundleUri);

      if (canLaunchNatively) {
        launchUrl(fbBundleUri);
      } else {
        await launchUrl(Uri.parse(fallbackUrl),
        
            mode: LaunchMode.externalApplication);
      }
    } catch (e, st) {
      // Handle this as you prefer
    }

Solution

  • You just have to set up a button for opening a link, that is Facebook link, NOT a share button.