flutterflutter-plugin

Flutter open facebook link in facebook app android & ios


In my app i have stored Facebook url's. I want to open them in facebook app not in browser. I tried using flutter_url_launcher package but it open the link in default browser ... What i want is to open the link directly into the facebook app . Can anyone suggest any solution or package to help me out of this situation?


Solution

  • I also used the solution from the link @ruelluna mentioned.

    Per current version, the below code worked for me:

    String fbProtocolUrl;
    if (Platform.isIOS) {
      fbProtocolUrl = 'fb://profile/page_id';
    } else {
      fbProtocolUrl = 'fb://page/page_id';
    }
    
    String fallbackUrl = 'https://www.facebook.com/page_name';
    
    try {
      bool launched = await launch(fbProtocolUrl, forceSafariVC: false);
    
      if (!launched) {
        await launch(fallbackUrl, forceSafariVC: false);
      }
    } catch (e) {
      await launch(fallbackUrl, forceSafariVC: false);
    }
    

    Also, make sure Info.plist file contains the following:

     <array> 
            <dict>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>fb[your_page_id]</string>
                </array>
            </dict>
        </array>
    

    You can take your_page_id from: https://findmyfbid.com/